Skip to content

Instantly share code, notes, and snippets.

@Waseem-Almoliky
Last active July 19, 2024 13:11
Show Gist options
  • Save Waseem-Almoliky/8aab02bdb8155a06cf5c2ef60fcdebea to your computer and use it in GitHub Desktop.
Save Waseem-Almoliky/8aab02bdb8155a06cf5c2ef60fcdebea to your computer and use it in GitHub Desktop.
yemeni phone numbers regex

السلام عليكم ورحمة الله وبركاته ، هذا كود ريجيكس للتحقق من صحة أرقام الجوالات اليمنية ، يقوم الريجيكس بالتحقق من مفتاح الدولة ، مفتاح شركات الإتصالات والخطوط الارضية لضمان صحة النص المدخل .

yemeni phone number regex

Hello

this is a regex code to validate yemeni phone number for private companies and ground lines almost everything :) hope you found it useful.

/^(((\+|00)9677|0?7)[01378]\d{7}|((\+|00)967|0)[1-7]\d{6})$/

Example code in JavaScript:

/^(((\+|00)9677|0?7)[01378]\d{7}|((\+|00)967|0)[1-7]\d{6})$/.test('737198225')

according to wiki info here https://en.wikipedia.org/wiki/Telephone_numbers_in_Yemen

I've updated the regex to validate the strict format

Regex Explanition: Regex code splited to 2 parts due to their diffrent rules first part for private companies and the second for ground lines. so first for private copnies.

starting with:

((\+|00)9677|0?7)[01378]\d{7}

(\+|00) match + or 00 for global

9677 the 967 is countery key and the last 7 in 9677 is a prefix for all companies in yemen

all above or:

0?7 thats mean if it's locale call it may start with 07 or 7

then:

[01378] yemeni compnies' code

0 for Y

1 for sabafon

3 for MTN

7 and 8 for yemen mobile

finally:

\d{7} 7 digits the customer number

all above was for praivte companies for ground lines:

((\+|00)967|0)[1-7]\d{6}

(\+|00) match + or 00 for global as before

967 is countery key as mentioned

all above or:

0 thats mean if it's locale call it may start with 0

then:

[1-7]

digits from 1 to 7

1 for sana'a

2 for Aden - Lahij - Abyan

3 Hodaidah

4 Ibb, Taiz

5 Hadramaut - Shabwah - Al Mahrah

6 Marib - Al Bayda - Al Jawf

7 Saddah - Hajjah - 'Amran - Al Mahwit

finally:

\d{6} 6 digits the customer number

hope it will help someone

any improvment is always welcomed.

@SabaWesabi
Copy link

Thanks alot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment