quick question

  • Thread starter Thread starter Troy
  • Start date Start date
T

Troy

Hello,

I'd like to validate an input my from user i.e. make sure that the user
enters the phone number is the following formats

(XXX) XXX-XXXX
XXX-XXX-XXXX

Any ideas on how I can achieve this with regular expressions? Having
difficulty wrapping my head around it.

thanks
 
Troy,

When you check it, you look for the pattern so code to do the same thing.
Check length of strings
Then for each case check for the digits and characters in the right place.

Any error jump out to a handler.

Doug
 
Quick answer.

Start with this. You should combine them into one.
^\(\d{3}\) \d{3}-\d{4}$-------(XXX) XXX-XXXX
^\d{3}-\d{3}-\d{4}$--------- XXX-XXX-XXXX
 
thanks for the quick answer but can I bother you to show me how to implement
your suggestion with system.text.regularexpression name space?

thanks
 
dim pattern as String =" ^\(\d{3}\) \d{3}-\d{4}$"
dim pattern2 as String="^\d{3}-\d{3}-\d{4}$"

If Regex.IsMatch(yourString, pattern) orelse Regex.IsMatch(yourString,
pattern2) then
'-- Match made. Do whaterver
End If
 
you rock man... thanks

Some Guy said:
dim pattern as String =" ^\(\d{3}\) \d{3}-\d{4}$"
dim pattern2 as String="^\d{3}-\d{3}-\d{4}$"

If Regex.IsMatch(yourString, pattern) orelse Regex.IsMatch(yourString,
pattern2) then
'-- Match made. Do whaterver
End If
 

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