south african phone number validation
-
hi guys, Iam try to validate a south african phone number. I have tried this but it won't work:
Regex rx = new Regex(((?:\\+27|27)|0)(72|82|73|83|74|84)(\\d{7}));
here is an example of numbers I would want to validate: - 0 74 3720198 - 0 72 3720198 - 27 74 3720198 - +27 74 3720198 Please help me if Iam making a mistake somewhere I have tried google but no help so far... Thanks, Morgan Freeman
-
hi guys, Iam try to validate a south african phone number. I have tried this but it won't work:
Regex rx = new Regex(((?:\\+27|27)|0)(72|82|73|83|74|84)(\\d{7}));
here is an example of numbers I would want to validate: - 0 74 3720198 - 0 72 3720198 - 27 74 3720198 - +27 74 3720198 Please help me if Iam making a mistake somewhere I have tried google but no help so far... Thanks, Morgan Freeman
I'm afraid I can't help much with the regex for SA numbers, as I don't know the ins-and-outs of how they are comprised. (Someone else here might be able to help directly), but this [free] tool will speed up validation: http://www.radsoftware.com.au/regexdesigner/[^] Also this could be of some help: http://regexlib.com/Search.aspx?k=south+africa[^]
Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter. Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
-
hi guys, Iam try to validate a south african phone number. I have tried this but it won't work:
Regex rx = new Regex(((?:\\+27|27)|0)(72|82|73|83|74|84)(\\d{7}));
here is an example of numbers I would want to validate: - 0 74 3720198 - 0 72 3720198 - 27 74 3720198 - +27 74 3720198 Please help me if Iam making a mistake somewhere I have tried google but no help so far... Thanks, Morgan Freeman
Your first problem is the spaces between the digits. Try something a bit simpler, and work your way up to the full expression: "((0\s)|(27\s))(?<AreaCode>[0-9]{2})(?<LocalNumber>\s[0-9]{7})" Feed this into Expresso[^] - examines and generates Regular expressions. It's free, and it really helps!
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
-
hi guys, Iam try to validate a south african phone number. I have tried this but it won't work:
Regex rx = new Regex(((?:\\+27|27)|0)(72|82|73|83|74|84)(\\d{7}));
here is an example of numbers I would want to validate: - 0 74 3720198 - 0 72 3720198 - 27 74 3720198 - +27 74 3720198 Please help me if Iam making a mistake somewhere I have tried google but no help so far... Thanks, Morgan Freeman
Hi, First of all, regular expression must be defined using a string, so you have to instanciate it that way :
Regex rx = new Regex("((?:\\+27|27)|0)(72|82|73|83|74|84)(\\d{7})");
Moreover, as OriginalGriff told you, consider using a tool like Expresso to build and test your regular expressions. Regards.
-
Your first problem is the spaces between the digits. Try something a bit simpler, and work your way up to the full expression: "((0\s)|(27\s))(?<AreaCode>[0-9]{2})(?<LocalNumber>\s[0-9]{7})" Feed this into Expresso[^] - examines and generates Regular expressions. It's free, and it really helps!
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
OriginalGriff wrote:
Your first problem is the spaces between the digits
thanks man, with spaces I was just trying to indicate where the full number is branched or divided I will try your idea and thanks alot Morg
-
I'm afraid I can't help much with the regex for SA numbers, as I don't know the ins-and-outs of how they are comprised. (Someone else here might be able to help directly), but this [free] tool will speed up validation: http://www.radsoftware.com.au/regexdesigner/[^] Also this could be of some help: http://regexlib.com/Search.aspx?k=south+africa[^]
Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter. Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
thanks man I will try your links and thanks alot Morg
-
Hi, First of all, regular expression must be defined using a string, so you have to instanciate it that way :
Regex rx = new Regex("((?:\\+27|27)|0)(72|82|73|83|74|84)(\\d{7})");
Moreover, as OriginalGriff told you, consider using a tool like Expresso to build and test your regular expressions. Regards.
Thanks man
-
Your first problem is the spaces between the digits. Try something a bit simpler, and work your way up to the full expression: "((0\s)|(27\s))(?<AreaCode>[0-9]{2})(?<LocalNumber>\s[0-9]{7})" Feed this into Expresso[^] - examines and generates Regular expressions. It's free, and it really helps!
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
hey hey thanks man that program is so cool, I managed to figure out what was wrong, the right expr: Regex rx = new Regex("((?:\+27|27)|0)(72|82|73|83|74|84)(\d{7})"); Great one!
-
hey hey thanks man that program is so cool, I managed to figure out what was wrong, the right expr: Regex rx = new Regex("((?:\+27|27)|0)(72|82|73|83|74|84)(\d{7})"); Great one!
I wish I'd written it! :laugh:
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy