0

I use this ^((\d-\d{3})|(\d{1,3}))\-\d{3}-\d{7}$ regex to validate phone numbers.

However it does not accept the following number which is valid. What is the problem? Could it have to do with the zeros at the end?

90-312-2488900 
4

2 回答 2

2

Your regexp seems to work properly.

Maybe the problem is in the last space in your example. Try to remove it with string.Trim, or add \s* to your regexp (or even add it between every groups of numbers.

于 2013-05-07T12:34:25.227 回答
0

The space at the end of your example is what is causing it to not match. Go to regexpal and type in your regex. When you try your example, it will show you what matches and what doesn't. Without the space, you are good to go. As JleruOHep recommended, try trimming the string, or allow whitespace in your regex.

Here is your phone number without whitespace at the end.

And with whitespace.

The yellow highlight is what matches.

于 2013-05-07T19:40:06.723 回答