Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <pre>Basic Validation (Format Only)</pre>
  <input id='ssn1' value='555-55-5555' /><button onclick='basicValidate(ssn1.value);'>Validate</button>
  <pre>Actual Validation (Using rules defined by the Social Security Administration)</pre>
  <input id='ssn2' value='555-55-5555'/><button onclick='actualValidate(ssn2.value);'>Validate</button>
  <pre>"Over-the-top" Validation (Handles previously mentioned rules and a few common exceptions)</pre>
  <input id='ssn3' value='555-55-5555' /><button onclick='overTheTopValidate(ssn3.value);'>Validate</button>
</body>
</html>
 
//Basic Validation (format only)
function basicValidate(ssn){
      //Build your expression
      var regex = new RegExp("^\\d{3}-\\d{2}-\\d{4}$");
      //Test your current value
      alert(regex.test(ssn));
}
//Actual Validation 
function actualValidate(ssn){
      //Build your expression
      var regex = new RegExp("^(?!219-09-9999|078-05-1120)(?!666|000|9\\d{2})\\d{3}-(?!00)\\d{2}-(?!0{4})\\d{4}$");
      //Test your current value
      alert(regex.test(ssn));
}
//"Over-the-top" Validation 
function overTheTopValidate(ssn){
      //Build your expression
      var regex = new RegExp("^(?!\\b(\\d)\\1+-(\\d)\\1+-(\\d)\\1+\\b)(?!123-45-6789|219-09-9999|078-05-1120)(?!666|000|9\\d{2})\\d{3}-(?!00)\\d{2}-(?!0{4})\\d{4}$");
      //Test your current value
      alert(regex.test(ssn));
}
  
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
rionmonsterpro
0viewers