473,387 Members | 1,624 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 1119
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.