Jump to content

Leading Zeros needed in a text field


iprint2

Recommended Posts

I need to have a minimum of 5 numbers in a field if 5 are not entered I need it to automatically fill with leading zeros. How can I make this happen. I was trying to use this to create an error alert, but it is not working either.

 

<script type="text/javascript">

 

//This needs to match the <input id= of the field that the url is entered in.

var EmployeeNumber = "EmployeeNumber";

 

 

document.getElementById(EmployeeNumber).onblur = alert_box;EmployeeNumber

 

function alert_box()

{

var EmployeeNumber= /^\(?([0-9]{5})\)$/;

 

if(!this.value.match(EmployeeNumber))

{

alert("This is not a valid number.Must be 5 digits. Use leading zeros if necessary. Example: 00001”);

this.value = "";

}

}

 

</script>

Link to comment
Share on other sites

I need to have a minimum of 5 numbers in a field if 5 are not entered I need it to automatically fill with leading zeros. How can I make this happen. I was trying to use this to create an error alert, but it is not working either.

 

<script type="text/javascript">

 

//This needs to match the <input id= of the field that the url is entered in.

var EmployeeNumber = "EmployeeNumber";

 

 

document.getElementById(EmployeeNumber).onblur = alert_box;EmployeeNumber

 

function alert_box()

{

var EmployeeNumber= /^\(?([0-9]{5})\)$/;

 

if(!this.value.match(EmployeeNumber))

{

alert("This is not a valid number.Must be 5 digits. Use leading zeros if necessary. Example: 00001”);

this.value = "";

}

}

 

</script>

 

You could try setting the Maximum Character Length of the field to 5 and use a JavaScript rule similar to this.

 

return FormatNumber("00000", Field("EmployeeNumber"));

Link to comment
Share on other sites

×
×
  • Create New...