admin管理员组文章数量:1389897
I need a regex that validates a proper SSN number displaying in Screen with mask.
However we show only last 4 digits of SSN and we mask other character with *
symbol
User can either enter only a number at the place of *
or they leave as it is.
User can enter valid input or they never change
***-**-1234
123-55-1234
User changed the displayed to Invalid SSN
5**-**-1234
A**-**-1234
AAA-5*-1234
Need a JavaScript Regex code/article for this.
I need a regex that validates a proper SSN number displaying in Screen with mask.
However we show only last 4 digits of SSN and we mask other character with *
symbol
User can either enter only a number at the place of *
or they leave as it is.
User can enter valid input or they never change
***-**-1234
123-55-1234
User changed the displayed to Invalid SSN
5**-**-1234
A**-**-1234
AAA-5*-1234
Need a JavaScript Regex code/article for this.
Share Improve this question asked Jun 26, 2013 at 12:18 Murali MurugesanMurali Murugesan 22.6k18 gold badges75 silver badges122 bronze badges 1- 1 and what have you tried? why didn't it work? – jbabey Commented Jun 26, 2013 at 12:19
1 Answer
Reset to default 6You can use the regex:
(\d{3}-\d{2}|\*{3}-\*{2})-\d{4}
To allow:
***-**-1234
123-55-1234
And nothing else.
Explanation:
\d
mean a digit (that is, any number from 0 to 9 (unicode digits as well));\d{3}-\d{2}
means 3 digits, followed by the char-
followed by 2 digits;\*{3}-\*{2}
means 3 chars*
, followed by the char-
followed by 2 chars*
;|
is the alternation operator. It means roughly "or", like(a|b)
means matcha
orb
;- So:
(\d{3}-\d{2}|\*{3}-\*{2})
means (3 digits, followed by the char-
followed by 2 digits) OR (3 chars*
, followed by the char-
followed by 2 chars*
). - Finally, the whole code
(...)-\d{4}
means the same as explained in the previous item followed by the char-
followed by 4 digits.
In summary, (\d{3}-\d{2}|\*{3}-\*{2})-\d{4}
means:
- ((3 digits, followed by the char
-
followed by 2 digits) OR (3 chars*
, followed by the char-
followed by 2 chars*
)), all followed by the char-
followed by 4 digits
本文标签: javascriptRegex for Validating SSN with *Stack Overflow
版权声明:本文标题:javascript - Regex for Validating SSN with * - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744613505a2615796.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论