I need regular expression for SSN, which satisfies the following condion.
- Can not accept or accept
666 in positions 1-3
000 in 1-3 posts Can not use or accept
00 in positions 4-5
0000 use in position 6-9 or Can not accept
- If the SSN starts with
9 ignore all other conditions.
Thank you in advance
description
It will be regex:
- Valid that string is 9 digits long
- If the first digit is not 9 then check the following
- all
6
- prevents status of 1,2 and 3, prevents position 1,2 and 3 from being all
0
- Prevents position 4 and 5 from all
0
- prevents status 6,7,8 and 9 from being all
0
^ (: (= [0-8]) (?! 666 | 000 | {3} 00 | {5} 0000) | ( = 9)? ..?) \ D {9} ( ?: \ R | \ n | \ Z)
PHP code example
You have not specified a language, so I am including this PHP example, for example how expression works
Input Text
000000000 000111111111001111111111111222222222333333333 444444444 555555555 666666666 666777777 777777777 888888888 999999999 123456789 123004567 123450000 923004567 923450000
Code
& lt ;? Php $ sourcestring = "your source string"; Preg_match_all ('/ ^ (: (?! 666 | 000 | {3} 00 | {5} 0000) | (= 9)) \ d {9} (? ..??: \ R | \ n | jade) / im ', $ sourcestring matches $); Echo "& lt; east & gt;" Print_r ($ match, true); ? & Gt; Array: ([0] => Array ([0] => 111111111 [/ 0] 1] => 222222222 [2] => 333333333 [3] => 444444444 [4] = & Gt; 555555555 [5] => 777777777 [6] => 888888888 [7] = 999999999 [8] = & gt; 123456789 [9] => 923004567 [10] = & Gt; 923450000))
- prevents status of 1,2 and 3, prevents position 1,2 and 3 from being all
- all
No comments:
Post a Comment