Link to home
Start Free TrialLog in
Avatar of Isaac
IsaacFlag for United States of America

asked on

Regular Expression validate SSN

How come the following does not work? What am I doing wrong?


<input type="text" id="ssn" placeholder="xxx-xx-xxxx">
<button id="ssValidate" onclick="valSSN()">
Validate
</button>

function valSSN(){
	var ssn = document.getElementById("ssn").value;
  var regExpression = /^[/d{3}]-[/d{2}]-[/d{4}]/;
  if(regExpression.test(ssn)){
  	alert("valid");
  }else{
  	alert("invalid");
  }
}

Open in new window



https://jsfiddle.net/isogunro/b3qdvufy/1/
SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial