Reputation: 539
I use this regex to recognize phone numbers in my app. "\\+?\\d{7,23}" But this cannot exclude decimal numbers like 3.1415926。
How to modify this regex, so that it can recognize phone numbers and do not give me decimal numbers like 3.1415926, 99.9999999。
In this case, the '1415926' and '9999999' will be recognized as phone number, which is not desired.
In a word, I want to reject numbers with '.' to be partially recognized as phone number. Or a phone number should not be succeeded with '.' or follow '.'.
Thanks.
Finally, I solved this problem using
Upvotes: 2
Views: 94
Reputation: 520938
Try this regex:
^\+?((?!\.)\d){7,23}$
Explanation:
\+ string starts with an optional +
((?!\.)\d){7,23} negative lookahead asserts that string contains between 7 and 23
numbers, each of which is not a dot
Demo here:
Upvotes: 2