Validate/Format Social Security Number

Posted on October 16, 2006

{{LEARN JAVASCRIPT HERE}}

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

Rate This script
Hot Scripts

 

Filed Under JavaScript |

Leave a Comment

If you would like to make a comment, please fill out the form below.

Name (required)

Email (required)

Website

Comments

1 Comment so far
  1. sanjeev September 20, 2007 7:08 am

    Thank you , i have tried this, i want to do more validation like validating the 9 digits - first three for Area code- next two-grouing. can this be possible.

    Thanks

    Regards
    Sanjeev