^(\+98|0)?9\d{9}$
var regex = new RegExp('^(\\+98|0)?9\\d{9}$');
var result = regex.test('+989031234567');
console.log(result);
^(\+98|0)?9\d{9}$
var regex = new RegExp('^(\\+98|0)?9\\d{9}$');
var result = regex.test('+989031234567');
console.log(result);
Have you found any edge cases in that one?
I think it's very accurate
(+98|0|98)9(0[1-5]|[1 3]\d|2[0-2]|98)\d{7}
Thanks for the sharing and also choosing the best RegEx Visualizer (I mentioned it for curious programmers)
But:
title
should be changed to "RegEx For Iranian Mobile Numbers"0098
should be acceptable too^
and $
?
tooSomething like:
((\+|00)98|0)9\d{9}
Hint: Persians and Arabs should be careful about difference between numbers on mobile keyboards while typing. Because
\d
can not detect Persian numbers.
For example :۰۱۲
!=123
So we have to replace all Persian/Arabic numbers before checking. RegEx for detecting :/[\u0660-\u0669\u06f0-\u06f9]/g
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:
for php guys
function is_phone($phone){
$pattern = '/(\+?98|098|0|0098)?(9\d{9})/';
return preg_match($pattern, $phone) ? true : false;
}
^0[1-8]{2}[0-9]{8}$
var regex = new RegExp('^0[1-8]{2,}[0-9]{8,}$');
var result = regex.test('02132621441');
console.log(result);
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}$/
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.
Hi kasir-barati
I test many thing but not work well, but yours was really great
thanks
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/
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
you can use /^(0|09|09[0-9]{1,9})$/
in onchangetext
hey guys
you can use this regex and enjoy:
/^((98|\+98|0098|0)*(9)[0-9]{9})+$/
in this you can validation persian phone number like:
9120000000
09120000000
00989120000000
+989120000000
989120000000
also you can see this git repository and use other regex validating, filtering, sanitizing and finding Persian strings in laravel framework and kotlin.
^09(1[0-9] |2[0-2] |3[0-9] |9[0-9]) [0-9]{7}$
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.
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
(+98|0|98|0098)?([ ]|-|[()]){0,2}9[0-9]([ ]|-|[()]){0,2}(?:[0-9]([ ]|-|[()]){0,2}){8}/
This is in fact much better