正式表达伊朗手机号码?

如何通过正则表达式测试用户手机号码。 伊朗手机有这样的数字系统:

091- --- ---- 093[1-9] --- ---- 

一些示例前缀:

 0913894---- 0937405---- 0935673---- 0912112---- 

资料来源: http : //en.wikipedia.org/wiki/Telephone_numbers_in_Iran

检测伊朗手机号码的最佳正则表达式

我确定它是检测伊朗手机号码的最佳正则表达式。

 (0|\+98)?([ ]|-|[()]){0,2}9[1|2|3|4]([ ]|-|[()]){0,2}(?:[0-9]([ ]|-|[()]){0,2}){8} 

在javascript中使用

 var mobileReg = /(0|\+98)?([ ]|-|[()]){0,2}9[1|2|3|4]([ ]|-|[()]){0,2}(?:[0-9]([ ]|-|[()]){0,2}){8}/ig, junkReg = /[^\d]/ig, persinNum = [/۰/gi,/۱/gi,/۲/gi,/۳/gi,/۴/gi,/۵/gi,/۶/gi,/۷/gi,/۸/gi,/۹/gi], num2en = function (str){ for(var i=0;i<10;i++){ str=str.replace(persinNum[i],i); } return str; }, getMobiles = function(str){ var mobiles = num2en(str+'').match(mobileReg) || []; mobiles.forEach(function(value,index,arr){ arr[index]=value.replace(junkReg,''); arr[index][0]==='0' || (arr[index]='0'+arr[index]); }); return mobiles; }; // test console.log(getMobiles("jafang 0 91 2 (123) 45-67 jafang or +۹۸ (۹۱۵) ۸۰ ۸۰ ۸۸۸")); 

支持所有这些选项

 912 123 4567 912 1234 567 912-123-4567 912 (123) 4567 9 1 2 1 2 3 4 5 6 7 9 -1 (2 12))3 45-6 7 and all with +98 or 0 +989121234567 09121234567 9121234567 

甚至是波斯数字

 +۹۸ (۹۱۵) ۸۰ ۸۰ ۸۸۸ 

并且仅检测真正的伊朗运算符编号091x 092x 093x 094x

欲了解更多信息: https : //gist.github.com/AliMD/6439187

^09\d{2}\s*?\d{3}\s*?\d{4}$

这也将允许数字之间的空格(如果它们是4-3-4)。

根据维基页面http://en.wikipedia.org/wiki/Telephone_numbers_in_Iran#Mobile_phones ,匹配是:

 091x-xxx-xxxx 0931-xxx-xxxx 0932-xxx-xxxx 0933-xxx-xxxx 0934-xxx-xxxx 0935-xxx-xxxx 0936-xxx-xxxx 0937-xxx-xxxx 0938-xxx-xxxx 0939-xxx-xxxx 

看起来像

 (the specific sequence 09) (1 followed by 0-9 OR 3 followed by 1-9) (7 digits) 

假设你现在不关心破折号,这意味着

 09 (1 [0-9] | 3 [1-9]) [0-9]{7} <-- spaces added for emphasis 09(1[0-9]|3[1-9])[0-9]{7} <-- actual regex 

(..|..)执行OR, [0-9]{7}表示正好匹配7位数,...)

如果您想在指定位置使用短划线:

 09(1[0-9]|3[1-9])-?[0-9]{3}-?[0-9]{4} 

应该匹配

简单就是美化生活。 试试这个:

 ^09[1|2|3][0-9]{8}$ //091 for Hamrahe-Aval Operator //092 for Rightel Operator //093 for Irancel Oprator 

这是c#中的一个Extension方法,我在我的项目中经常使用:

 public static bool IsValidMobileNumber(this string input) { const string pattern = @"^09[1|2|3][0-9]{8}$"; Regex reg = new Regex(pattern); return reg.IsMatch(input); } 

使用这样:

 If(!txtMobileNumber.Text.IsValidMobileNumber()) { throw new Exception("Mobile number is not in valid format !"); } 

首先让我们为数字写一个reg ex

^09\d{9}$表示必须从09开始,然后是9位数

或者代替\ d,你可以在那之后使用^ 09 [0-9] {9} $

 Regex objNotNaturalPattern=new Regex("[^09[0-9]{9}]"); 

objNotNaturalPattern.IsMatch(yourPhoneNumber);

希望这可以帮助。

\A09\d{9}应该为你做

 string sPattern = "^09[-.\\s]?\\d{2}[-.\\s]?\\d{3}[-.\\s]?\\d{4}$"; if (System.Text.RegularExpressions.Regex.IsMatch(stringToMatch, sPattern)){ System.Console.WriteLine("Phone Number is valid"); } else { System.Console.WriteLine("Phone Number is invalid"); } 

上面的表达式将匹配以09开头的任何数字,后跟空格,点或短划线(如果存在),然后是2位数等

例如:09001234567或09 11 123 4567或09-01-123-4567或09.01.123.4567或0900.000.0000或0900-000-0000或0900.000-0000等

/ ^({(09)([1-3]){2} – ([0-9]){7,7}}?)$ /

火柴:

 - 0913-1234567 - 0933-1234567 

不匹配:

 - 0944-1234567 - 0955-1234567 

如果您不想要’ – ‘,只需将其从正则表达式中删除即可

^ 09(1 \ d | 3 [1-9]) – \ d {3} – \ d {4} $

是您需要的正则表达式:

从字符串的开头开始(所以没有其他数字潜入)

09是不变的

1可以与任何后续数字组合,3不能与0组合

– ,和3位数

– ,和4位数

字符串结束(再次,所以没有其他数字潜入)

…但是不要相信我的话,运行它(我建议添加更多的测试号码):

  List possible = new List { "091-555-8888", "0915-888-4444", "0930-885-8844", "0955-888-8842" }; string regex = @"09(1\d|3[1-9])-\d{3}-\d{4}$"; foreach (string number in possible) { Console.WriteLine("{0} is{1} an Iranian number", number, Regex.IsMatch(number, regex) ? "" : " not"); } 

要支持0903 —- Irancell手机号码,请使用:

 ^(0|\+98)?([ ]|,|-|[()]){0,2}9[0|1|2|3|4]([ ]|,|-|[()]){0,3}(?:[0-9]([ ]|,|-|[()]){0,2}){8}$ 

这个怎么样 ?

^(\+98?)?{?(0?9[0-9]{9,9}}?)$

为…卖力:

09036565656

09151331685

09337829090

09136565655

09125151515

989151671625

9809152251148

在这里查看结果

在JavaScript中,您可以使用此代码

 let username = 09407422054 let checkMobile = username.match(/^0?9[0-9]{9}$/) 

它会回来

 ["9407422054", index: 0, input: "9407422054", groups: undefined]