Validate/Format Phone Numbers
Posted on October 16, 2006
The purpose of this script is to format and validate Telephone Numbers in a form field. The script strips all non-numeric characters and then validates that the remaining characters are sufficient to make up a valid phone number. If there remaining string is 10 characters in length, the script then formats by adding a “-” after the third and sixth digits. Resulting in a mask like ###-###-####.
The example script does the validation/formatting onBlur, meaning when the cursor leaves the Phone Number field. You can also set the event to happen onSubmit or onClick of the Submit button, etc.
View the script in action
Download the script here (< 2kb) Current Download Count: 5434
Filed Under JavaScript | Leave a Comment
Validate/Format Social Security Number
Posted on October 16, 2006
The purpose of this script is to format and validate Social Security Numbers in a form field. The script strips all non-numeric characters and then validates that the remaining characters are sufficient to make up a valid SSN. If there remaining string is 9 characters in length, the script then formats by adding a “-” after the third and fifth digits. Resulting in a mask like ###-##-####.
The example script does the validation/formatting onBlur, meaning when the cursor leaves the SSN field. You can also set the event to happen onSubmit or onClick of the Submit button, etc.
View the script in action
Download the script here (< 2kb) Current Download Count: 4372
Filed Under JavaScript | 1 Comment
Automatically Put the Cursor in a Form Field
Posted on October 2, 2006
Setting the focus, or for beginners, automatically placing the cursor in one of the fields of your HTML form, is fairly simple. There are two common methods. The first and most common is to use the <BODY> tag’s onload event.
Ex.
<body onload="document.FORMNAME.FIELDNAME.focus();">
However, there are times that you cannot use the body tag and you need another solution. As an alternative to the onLoad event, you can use the setTimeout fuction in JavaScript to wait half a second and then set the focus.
Ex.
<script>
setTimeout(’document.FORMNAME.FIELDNAME.focus()’,500);
</script>
In both cases, you would replace FORMNAME with the value of the name attribute in the <form> tag. You replace FIELDNAME with the value of the name attribute in the <input> tag of the targeted field.
Filed Under JavaScript | Leave a Comment
