I am trying to find the matching pattern in my phone no for not starts with some string.
For example:
Input: +551234467 Pattern: Not start with +55
Input: 557875756 Pattern: Not start with 55
So far I have tried many patterns and some gives result for only the strings without +.
/[^(\\+55)]/
/^(?!\\+55).*$/
/[?!\\+5|55]{2}/
/[^\\+55|^\\+5|^55]/
Someone please help me on this. Thank you.
I forget to mention one more use case as 557875756 also should not match. Means +55 & 55 - by OP in comment to the question
Use following regex.
^\+?(?!55)\d+$
^
: Starts with Anchor \\+?
: Matches zero or one +
symbol (?!55)
: Negative look-ahead, does not match 55 \\d+
: Matches one or more digits $
: Ends with Anchor Demo
input:valid { color: green; } input:invalid { color: red; }
<input type="text" pattern="\\+?(?!55)\\d+" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.