468,133 Members | 1,240 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,133 developers. It's quick & easy.

quick question

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
Nov 21 '05 #1
5 977
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

"Troy" <ma****@pushit.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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

Nov 21 '05 #2
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

"Troy" <ma****@pushit.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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

Nov 21 '05 #3
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

"Some Guy" <my*****@there.com> wrote in message
news:11*************@corp.supernews.com...
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

"Troy" <ma****@pushit.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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


Nov 21 '05 #4
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

"Troy" <ma****@pushit.com> wrote in message
news:eH*************@TK2MSFTNGP10.phx.gbl...
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

"Some Guy" <my*****@there.com> wrote in message
news:11*************@corp.supernews.com...
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

"Troy" <ma****@pushit.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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



Nov 21 '05 #5
you rock man... thanks

"Some Guy" <my*****@there.com> wrote in message
news:11*************@corp.supernews.com...
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

"Troy" <ma****@pushit.com> wrote in message
news:eH*************@TK2MSFTNGP10.phx.gbl...
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

"Some Guy" <my*****@there.com> wrote in message
news:11*************@corp.supernews.com...
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

"Troy" <ma****@pushit.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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



Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.