Regex for EIN number and SSN number format in jquery
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>
For SSN's:
http://regexlib.com/Search.aspx?k=ssn
For EINs:
http://regexlib.com/REDetails.aspx?regexp_id=1990