Validating the first 3 characters of a phone number

mike55

Well-known member
Joined
Mar 26, 2004
Messages
726
Location
Ireland
I need to validate the first two characters of a mobile phone number. I know that the length of the number is 10 characters, and that the first two will be 0 and 8. The third character can be either 5, 6, 7, or 8.

I have been going through various tutorials, but I am hitting a brick wall.

Mike55.
 
Phone number regex

A regular expression to validate the entire number might look like this:

Code:
\b08[5-8][0-9]{7}\b

If the first number is anything but 0, there will be no match.
If the second number is anything but 8, there will be no match.
If the third number is anything but 5, 6, 7 or 8 there will be no match.
If the total length of the number is not exactly 10, there will be no match.

You can test your regexes at somewhere like REGex TESTER.

Good luck :cool:
 
can you use the substring to get the first 3 numbers and then seperate the 3 through a loop and compare?

Code:
dim str as string = "0123456789"
str = str.substring(0,3)  str = "012"
for intL as integer = 1 to 3
   break down and compare code here
end for

or if you know the first to always the same, and need to check the last number

Code:
dim str as string = "0123456789" string of the number
str = str.substring(0,3)  str = "012"
dim boolCompare as boolean

boolCompare = str.EndsWith("5") If the 3 digits in with 5 then will return true

Ho[pefully this will get you on yor way.
 
Back
Top