'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 />
Solution 1:[1]
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}$
Solution 2:[2]
<input pattern="^(00201|\+201|01)[0-2,5]{1}[0-9]{8}$" >
- This validates if the number starts with the country code
00201,+201, or01 - Validate that the telecoms company prefix is correct
- validate if contain 7 numbers after its, and in the end of the number.
Solution 3:[3]
in 2021 i will add new mobile providers 015
^01[0-2,5]\d{8}$
Solution 4:[4]
Just use this Regexp:
/^01[0125][0-9]{8}$/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | zhulien |
| Solution 2 | Ali Atef |
| Solution 3 | Hosam Elzagh |
| Solution 4 | nos nart |
