I am wanting to build a validator (javascript) that can validate numbers from different countries,
I want to be able to call it using this skeleton phone('NZ', '049234567', false, false);
which is ‘COUNTRY PREFIX`, ‘NUMBER’, ‘LANDLINE’, ‘INTERNATIONAL’.
How would I go about doing such a thing?
Currently I am thinking of having something like
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]
]
}
}
}
See: http://en.wikipedia.org/wiki/List_of_country_calling_codes