Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex for EIN number and SSN number format in jquery

For jquery validation i need regex for SSN number format and EIN number format

EIN number like 52-4352452

SSN number like 555-55-5555

like image 529
yogeswaran K Avatar asked Nov 22 '10 05:11

yogeswaran K


2 Answers

For SSN's:

http://regexlib.com/Search.aspx?k=ssn

For EINs:

http://regexlib.com/REDetails.aspx?regexp_id=1990

like image 141
Robert Harvey Avatar answered Sep 20 '22 17:09

Robert Harvey


Our Needs

  • No prefix restrictions.
  • 9-digit EIN, hyphen optional.
  • With the hyphen, acceptable format: 00-0000000.

Regular Expression

^\d{2}\-?\d{7}$

Demonstrated with JavaScript/jQuery

<input type="text" id="ein1" value="0112345-67" />
<input type="text" id="ein2" value="01-1234567" />
<input type="text" id="ein3" value="011234567" />

<script type="text/javascript">
    var patternEIN = /^\d{2}\-?\d{7}$/;

    patternEIN.test($('#ein1').val()); // fail
    patternEIN.test($('#ein2').val()); // pass
    patternEIN.test($('#ein3').val()); // pass
</script>
like image 43
fusion27 Avatar answered Sep 22 '22 17:09

fusion27