Formatting phone numbers input

  • Thread starter Thread starter RD
  • Start date Start date
R

RD

We always have to have an area code but user does not always have to dial
the long distance digit 1 before the area code.
When user does not have to make long distance call the phone number our
format is like (450) 123-4560.
When he does have to make a long distance call its like 1 (450) 123-4560.
I'm wondering how to specify the input mask to allow for both these cases..

Any help would greatly appreciated.

Thanks
RD
 
Try Regex

Dim reg As Regex
Dim pattern As String = "^1?\s?\(\d{3}\)\s?\d{3}-\d{4}$"
Dim number As String = "(450) 123-4560"
' Dim number As String = "1 (405) 123-4560"

Debug.WriteLine reg.IsMatch(number, pattern).ToString
 
Oops, forget what I said.


Some Guy said:
Try Regex

Dim reg As Regex
Dim pattern As String = "^1?\s?\(\d{3}\)\s?\d{3}-\d{4}$"
Dim number As String = "(450) 123-4560"
' Dim number As String = "1 (405) 123-4560"

Debug.WriteLine reg.IsMatch(number, pattern).ToString
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top