Skip to content

Instantly share code, notes, and snippets.

@MoienTajik
Last active June 10, 2024 22:59
Show Gist options
  • Save MoienTajik/acd3dbb359054bd22e06cc97281934eb to your computer and use it in GitHub Desktop.
Save MoienTajik/acd3dbb359054bd22e06cc97281934eb to your computer and use it in GitHub Desktop.
Regex For Iranian Mobile Phone Numbers

Regex For Iranian Phone Numbers

This regex supports all kinds of Iranian mobile phone numbers :

^(\+98|0)?9\d{9}$


Regex Visualized

Usage in JavaScript :

var regex = new RegExp('^(\\+98|0)?9\\d{9}$');
var result = regex.test('+989031234567');

console.log(result);

Regex Tester Demo

JSFiddle Demo

@m-nt
Copy link

m-nt commented May 7, 2024

I think this is much much better: ^(0|0098|\+98)9(0[1-5]|[1 3]\d|2[0-2]|98)\d{7}$

Side notes:

  • And as @PAPIONbit mentioned you need to sanitize the data before validation.
  • And I like to save one format in the database: so I convert all phone numbers to 0098 (for Iran), and for an international app I would like to prefix all numbers with their country code.

RegEx Visualizer

This one works perfectly, also a small change so its works for this format to : 9110000000
edited regex: /^(0|0098|\+98|)9(0[1-5]|[1 3]\d|2[0-2]|98)\d{7}$/i

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