3 digit UD field with leading zeros

ud
e10

(Andris Skulte) #1

I’ve got to add a field that shows 3 digits, and keep the leading zeros.

Am I forced to set up the UD field as string x(3), then use the extended properties wizard to set the field mask to 999?

Or is there a better way? Thanks for the help!

(this thread was super helpful - Can't get EpiNumericEditor to display an integer. V10.1.400.18. Thanks Rob and Jose!)


(Mike Watkinson) #2

How are you using the leading zeros? Did you try just setting the UD field up as an integer with 999 for the format?


(Andris Skulte) #3

Hi Mike,

The 3 digits are part of an identification number that we match with a string in payments.

The original UD field was an integer, so it stripped the leading zeros. Integers treat “012” as “12”, and save it as “12”.

I created a new UD field of string type, formatted to x(3), and it works as intended.

Setting the field mask to 999 didn’t work. Guessing because that’s for numbers, not strings… A co-worker also gave me the following code to restrict the data entry to digits only, which was added to the form:

    	private void txtLastThree_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    	{
    		e.Handled = ! (char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar));
    	}