Reputation: 14852
I use masked input in browser and I want to use regex inside html5 attribute on input field - pattern
. Phone number example:
+375 (33) 302-66-60
Now I have regex:
^\D*(?:\d\D*){12,}$
But I want to check codes inside ()
. Now in Belarus we have only four possible code: 17
, 29
, 33
, 44
.
I will add correct answer to the library of regex at regex101.com for the keywords Belarus
and phone
. Thank you for answer.
Upvotes: 0
Views: 2303
Reputation: 61
I would probably go with something along the lines of
^\+375 \((17|29|33|44)\) [0-9]{3}-[0-9]{2}-[0-9]{2}$
This regex captures the national code +375
if you want to make it optional, you could always put it in parenthesis and add a ?
after.
Upvotes: 2
Reputation: 581
I would use this snippet
^+375 ((17|29|33|44)) [0-9]{3}-[0-9]{2}-[0-9]{2}$
^\+375
catches the country calling code (17|29|33|44)
catches the four different area codes and [0-9]{3}-[0-9]{2}-[0-9]{2}$
the rest.
Upvotes: 0