Reputation: 1533
What regex do I need to put into pattern
to make sure the inputted number start with "011", "012" or "010" and then 8 digits?
Example of wanted output:
012 XXXXXXXX
011 XXXXXXXX
010 XXXXXXXX
Note : X is any number from [0-9].
<input type="number" pattern="" required />
Upvotes: 1
Views: 8305
Reputation: 90
How about:
<input type="tel" pattern="^01[0-2]\d{1,8}$" required />
If you need or want only one space you can also use:
^01[0-2]\s\d{1,8}$
EDIT:
As Roland has mentioned, you should also use type="tel", instead of number, otherwise the pattern will be ignored.
Upvotes: 5
Reputation: 11
<input pattern="^(00201|\+201|01)[0-2,5]{1}[0-9]{8}$" >
00201
, +201
, or 01
Upvotes: 1
Reputation: 251
This is the regular expression for mobile phone numbers in Egypt for the 4 major Service providers:
^01[0-2,5]{1}[0-9]{8}$
Upvotes: 4