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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…