伊朗手机号码正则表达式? [英] Regular expression for Iranian mobile phone numbers?

查看:418
本文介绍了伊朗手机号码正则表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

一些示例前缀:

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



来源:<一个HREF =htt​​p://en.wikipedia.org/wiki/Telephone_numbers_in_Iran相对=nofollow> 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 = [/ 0 / GI,/ 1 / GI,/ 2 / GI ,/ 3 / GI,/ 4 / GI,/ 5 / GI,/ 6 / GI,/ 7 / GI,/ 8 / GI,/ 9 / GI],
num2en =功能(STR){
为(VAR I = 0;我小于10;我++){$​​ b $ b海峡= str.replace(persinNum [I],I);
}
返回海峡;
},
getMobiles =功能(STR){
变种手机= num2en(STR +'')。比赛(mobileReg)|| [];
mobiles.forEach(功能(价值指数,编曲){
ARR [指数] = value.replace(junkReg,'');
ARR [指数] [0] === '0'||(ARR [指数] ='0'+ ARR [指数]);
});
返回手机;
};

//测试
的console.log(getMobiles(jafang 0 2 91(123)45-67 jafang或+98(915)80 80 888));






支持像所有这些选项



  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
和所有与+98或0
989121234567
09121234567
9121234567

甚至波斯号

  +98(915)80 80 888 

和只有真正的检测操作人员的伊朗数091x 092x 093x 094x



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


how can i test user mobile phone number via regular expression. Iran Mobile phone has numeral system like this:

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

Some example prefixes:

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

Source: http://en.wikipedia.org/wiki/Telephone_numbers_in_Iran

解决方案

Best Regular Expression for Detect Iranian Mobile Phone Numbers

I'm sure its best regular expression for detect iranian mobile number.

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


use in 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 +۹۸ (۹۱۵) ۸۰ ۸۰ ۸۸۸"));


support all option like these

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

or even persian numbers

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

and only detect true iranian operator numbers 091x 092x 093x 094x

for more info : https://gist.github.com/AliMD/6439187

这篇关于伊朗手机号码正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆