Skip to content

Instantly share code, notes, and snippets.

@MoienTajik
Last active June 22, 2026 20:12
Show Gist options
  • Select an option

  • Save MoienTajik/acd3dbb359054bd22e06cc97281934eb to your computer and use it in GitHub Desktop.

Select an option

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

@kasir-barati

kasir-barati commented Aug 4, 2021

Copy link
Copy Markdown

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

@AliVP97

AliVP97 commented Jun 13, 2022

Copy link
Copy Markdown

Regex For Iranian Home Phone Numbers

This regex supports all kinds of Iranian home phone numbers :

^0[1-8]{2}[0-9]{8}$


Regex Visualized

Usage in JavaScript :

var regex = new RegExp('^0[1-8]{2,}[0-9]{8,}$');
var result = regex.test('02132621441');

console.log(result);

Regex Tester Demo

@abolfazl-sh1

Copy link
Copy Markdown

The most complete regex For Iranian Phone Numbers:
/^(0|0098|+98)9(0[1-5]|[1 3]\d|2[0-2]|9[0-4]|98)\d{7}$/

@mes-mojahed

Copy link
Copy Markdown

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

Hi kasir-barati
I test many thing but not work well, but yours was really great
thanks

@amirgholikhani

amirgholikhani commented May 27, 2023

Copy link
Copy Markdown

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

You can test it to make sure it works. This RegEx has also been updated.
https://regex101.com/

@AmirMahdyJebreily

Copy link
Copy Markdown

Here we have a whole regex that validates Iranian phone numbers by separating the operator from each other
https://github.com/AmirMahdyJebreily/iranian-phonenumber-validation/graphs/traffic

@omidgharib

Copy link
Copy Markdown

you can use /^(0|09|09[0-9]{1,9})$/ in onchangetext

@AzMostafa

AzMostafa commented Jan 10, 2024

Copy link
Copy Markdown

hey guys
you can use this regex and enjoy:
/^((98|\+98|0098|0)*(9)[0-9]{9})+$/

look at this image:
image (1)

in this you can validation persian phone number like:

  1. with_out_zero: 9120000000
  2. with_zero: 09120000000
  3. with_zero_code: 00989120000000
  4. with_plus: +989120000000
  5. with_out_plus: 989120000000

also you can see this git repository and use other regex validating, filtering, sanitizing and finding Persian strings in laravel framework and kotlin.

@rezacloner1372

Copy link
Copy Markdown

^09(1[0-9] |2[0-2] |3[0-9] |9[0-9]) [0-9]{7}$

@m-nt

m-nt commented May 7, 2024

Copy link
Copy Markdown

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

@Rava-milad

Copy link
Copy Markdown

this support all new mobile operator format
/^09(0[1-5]|1[0-9]|2[012]|3[0235-9]|9[0-4]|98|99)\d{7}$/

@m-nt

m-nt commented Nov 16, 2025

Copy link
Copy Markdown

this support all new mobile operator format
/^09(0[1-5]|1[0-9]|2[012]|3[0235-9]|9[0-4]|98|99)\d{7}$/

this doesn't include +989000000000

@Rava-milad

Copy link
Copy Markdown

For that you can use this regex: /(^(0?9)|(\+?989))((14)|(13)|(12)|(19)|(18)|(17)|(15)|(16)|(11)|(10)|(90)|(91)|(92)|(93)|(94)|(95)|(96)|(32)|(30)|(33)|(35)|(36)|(37)|(38)|(39)|(00)|(01)|(02)|(03)|(04)|(05)|(41)|(20)|(21)|(22)|(23)|(31)|(34)|(9910)|(9911)|(9913)|(9914)|(9999)|(999)|(990)|(9810)|(9811)|(9812)|(9813)|(9814)|(9815)|(9816)|(9817)|(998))\W?\d{3}\W?\d{4}/gm

I should mention that in my previous regex I only focused on validating real Iranian mobile number prefixes rather than just the general phone number structure, and since in my environment there was no need for supporting the “+98” format, I didn’t include it.
This new regex is taken from the Iranian Phone Number Validation repository, which provides a more complete and standardized list of valid prefixes.

@m-nt

m-nt commented Nov 29, 2025

Copy link
Copy Markdown

👌👌

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