xpredo
xpredo

Reputation: 1533

HTML5 pattern phone number In Egypt

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

Answers (5)

Heisoka
Heisoka

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

Mahmmoud Kinawy
Mahmmoud Kinawy

Reputation: 891

Just use this Regexp:

/^01[0125][0-9]{8}$/

Upvotes: 1

Ali Atef
Ali Atef

Reputation: 11

<input pattern="^(00201|\+201|01)[0-2,5]{1}[0-9]{8}$" >
  1. This validates if the number starts with the country code 00201, +201, or 01
  2. Validate that the telecoms company prefix is correct
  3. validate if contain 7 numbers after its, and in the end of the number.

Upvotes: 1

xpredo
xpredo

Reputation: 1533

in 2021 i will add new mobile providers 015

^01[0-2,5]\d{8}$

Upvotes: 0

Mohammed Adel
Mohammed Adel

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

Related Questions