There came another requirement.
When the user didn't key in the max length in the first text box, leading zero(s) will automatically be added to fill up the space.
Telephone number: (12)-(12345678)
If the user only entered "12", it hasn't reached the max length (3) yet, then a leading zero will be added to become "012".
//Check if the value length hasn't reach its max length yet
if (currentField.value.length != currentField.maxLength)
//Add leading zero(s) in front of the value
var numToAdd = currentField.maxLength - currentField.value.length;
var value ="";
for (var i = 0; i < numToAdd;i++)
value += "0";
currentField.value = value + currentField.value;
Copy this function in the code file:
public static void AddLeadingZeroAttribute(TextBox txt)
//Add leading zero when focus is lost
"OnBlur" event will be triggered when the textbox loses the focus.
Whenever the user finished keying in values and left the textbox, the AddLeadingZero() function will be called.