我想建立一个验证器(JavaScript)的,可以从不同国家的验证号码,列表格式
我希望能够用这个骨架phone('NZ', '049234567', false, false);
这是称之为“COUNTRY PREFIX“,”NUMBER“,”LANDLINE“,”国际“。
我该如何去做这样的事情?
目前,我在想有什么样的
var phones = {
NZ: {
national: {
landline: [
'03{2,9}n(6)', //read as 03[a number between 2 and 9][a random number][repeat previous expression 6 times]
'04{2,9}n(6)', //read as 04[a number between 2 and 9][a random number][repeat previous expression 6 times]
'06{2,9}n(6)', //read as 06[a number between 2 and 9][a random number][repeat previous expression 6 times]
'07{2,9}n(6)', //read as 07[a number between 2 and 9][a random number][repeat previous expression 6 times]
'09{2,9}n(6)' //read as 09[a number between 2 and 9][a random number][repeat previous expression 6 times]
],
mobile: [
'020n(7,10)', //read as 020[a random number][repeat previous expression between 7 and 10 times]
'021n(7,10)', //read as 021[a random number][repeat previous expression between 7 and 10 times]
'022n(7,10)', //read as 022[a random number][repeat previous expression between 7 and 10 times]
'027n(7,10)', //read as 027[a random number][repeat previous expression between 7 and 10 times]
'029n(7,10)' //read as 029[a random number][repeat previous expression between 7 and 10 times]
]
},
international: {
landline: [
'+643{2,9}n(6)', //read as +643[a number between 2 and 9][a random number][repeat previous expression 6 times]
'+644{2,9}n(6)', //read as +644[a number between 2 and 9][a random number][repeat previous expression 6 times]
'+646{2,9}n(6)', //read as +646[a number between 2 and 9][a random number][repeat previous expression 6 times]
'+647{2,9}n(6)', //read as +647[a number between 2 and 9][a random number][repeat previous expression 6 times]
'+649{2,9}n(6)' //read as +649[a number between 2 and 9][a random number][repeat previous expression 6 times]
],
mobile: [
'+6420n(7,10)', //read as +6420[a random number][repeat previous expression between 7 and 10 times]
'+6421n(7,10)', //read as +6421[a random number][repeat previous expression between 7 and 10 times]
'+6422n(7,10)', //read as +6422[a random number][repeat previous expression between 7 and 10 times]
'+6427n(7,10)', //read as +6427[a random number][repeat previous expression between 7 and 10 times]
'+6429n(7,10)' //read as +6429[a random number][repeat previous expression between 7 and 10 times]
]
}
}
}
您好, 欢迎您的回答,这看起来非常类似于我在做什么(请参阅我的编辑)您有任何其他建议吗? – Hailwood 2011-03-09 01:50:41
如果这只是验证而不是格式化,是的 - 但我会使用标准的正则表达式格式,而不是您自己的自制规范。 ''^ \ + 649 [2-9] \ d {6,6} $''(我不确定JavaScript的正则表达式格式) - http://en.wikipedia.org/wiki/Regular_expression解释了正则表达式一般。 – Dre 2011-03-09 01:58:42
好吧,我说谎了一点,没有太多的验证,但为了生成有效的虚拟数据(其谷歌铬扩展im建立,这是用来帮助填写表单与测试数据) – Hailwood 2011-03-09 02:43:30