Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

Summary

I want to have an Index Field that must have 5 numbers and not strip out leading zeros. How can this be done in a Validation script?

Answer/Solution

You can implement the IFormatProvider parameter of the ToString function as follows:

Private Sub Name0_FieldPostProcessing(sender As Object, e As PostFieldEventArgs) Handles Name0.FieldPostProcessing

Name0.IndexField.Value = CInt(Name0.IndexField.Value).ToString("D5")

End Sub

This only works with numerical input from the user so, you will need to check that an actual number was entered. Any other character will throw an exception.

CInt converts the input string to an Integer.

The "D5" passed to the ToString function tells it to format the integer to pad zeros at the left of the string to full length of five characters.

  • No labels