Created
April 2, 2012 21:14
-
-
Save wesleyvicthor/2287261 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
regex=/^([1-9][1-9] +|\([1-9][1-9]\) *)[1-9]\d{2,4}[ .-]?\d{4}$/; | |
strings=[ | |
/* Só numéricos com espaços que casam */ | |
'11 9990000', | |
'11 99990000', | |
'11 999990000', | |
'11 999 0000', | |
'11 9999 0000', | |
'11 99999 0000', | |
/* Só numéricos com espaço e "." que casam */ | |
'11 999.0000', | |
'11 9999.0000', | |
'11 99999.0000', | |
/* Só numéricos com espaço e "-" que casam */ | |
'11 999-0000', | |
'11 9999-0000', | |
'11 99999-0000', | |
/* Numéricos com parênteses e espaços que casam */ | |
'(11) 9990000', | |
'(11) 99990000', | |
'(11) 999990000', | |
'(11) 999 0000', | |
'(11) 9999 0000', | |
'(11) 99999 0000', | |
'(11)999 0000', | |
'(11)9999 0000', | |
'(11)99999 0000', | |
/* Numéricos com parênteses, espaço e "." que casam */ | |
'(11) 999.0000', | |
'(11) 9999.0000', | |
'(11) 99999.0000', | |
'(11)999.0000', | |
'(11)9999.0000', | |
'(11)99999.0000', | |
/* Numéricos com parênteses, espaço e "-" que casam */ | |
'(11) 999-0000', | |
'(11) 9999-0000', | |
'(11) 99999-0000', | |
'(11)999-0000', | |
'(11)9999-0000', | |
'(11)99999-0000', | |
/* Strings estranhas que casam por causa do uso de " *" e não de " ?" */ | |
'11 999-0000', | |
'11 99990000', | |
'11 999990000', | |
'(11) 999990000', | |
/* Strings que casariam se a regex usasse "\s*" em vez de " *" */ | |
"99\n99999999", | |
"999999\n9999", | |
/* Strings que não casam */ | |
'(11) 099.0000', | |
'11) 99999-9999', | |
'(11 999999999', | |
'11 00.9999', | |
'11999-0000', | |
'119999-0000', | |
'1199999-0000', | |
'11999.0000', | |
'119999.0000', | |
'1199999.0000', | |
'119990000', | |
'1199990000', | |
'11999990000', | |
'11999 0000', | |
'119999 0000', | |
'1199999 0000', | |
]; | |
strings.map(function (string) { | |
if (regex.test(string)) { | |
console.info(string); | |
} else { | |
console.warn(string); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment