Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

A Client refers to the person who incurs the development cost.

A Customer refers to the person that pays to use the product.

------

My software never has bugs. It just develops random features. (Mosabama vbforums.com)

Posted

Phone number regex

 

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

 

\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:

Never trouble another for what you can do for yourself.
Posted

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

 

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

 

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.

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...