473,406 Members | 2,894 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,406 software developers and data experts.

Validate US Phone number with Regular Expression

Ori
Hi,

I'm looking for a good way to validate a US phone number and i though
using regular expression for this.
I want to support 3 different ways to enter a phone number:
1.Local Phone : 888-8899
2.With extension: (310)888-2569
3.With extension + 1 : 1(888)789-2569

Can someone tell me what expression I can us in order to support those
3 methods at once ?

Thanks,

Ori.
Nov 18 '05 #1
2 3985
I feel it's much more rewarding to do your own regex's, unless you are
really stumped at something (this example is not that hard by the way)

If you would like to learn how to do it yourself, I would suggest this site,
it has many examples. http://regexplib.com

And there are many tutorial sites to help you as well.
http://gnosis.cx/publish/programming...pressions.html
http://www.regular-expressions.info/

Basically the easiest way to do this one is to use the | delimiter to
specify three different regex's for each phone number.
firstway|secondway|thirdway. The first way would be something like this
\d{3}-\d{4}. If you really wanted to have fun, you could probably do this
without using the | operator, but I wouldn't do that if this is your first
regex experience.

HTH,
--Michael

"Ori" <or*******@hotmail.com> wrote in message
news:b4**************************@posting.google.c om...
Hi,

I'm looking for a good way to validate a US phone number and i though
using regular expression for this.
I want to support 3 different ways to enter a phone number:
1.Local Phone : 888-8899
2.With extension: (310)888-2569
3.With extension + 1 : 1(888)789-2569

Can someone tell me what expression I can us in order to support those
3 methods at once ?

Thanks,

Ori.

Nov 18 '05 #2
Check out the RegularExpressionValidator control

The designer will give you a starting point (check the ValidationExpression
property in the property browser)

HTH
Brian W

"Ori" <or*******@hotmail.com> wrote in message
news:b4**************************@posting.google.c om...
Hi,

I'm looking for a good way to validate a US phone number and i though
using regular expression for this.
I want to support 3 different ways to enter a phone number:
1.Local Phone : 888-8899
2.With extension: (310)888-2569
3.With extension + 1 : 1(888)789-2569

Can someone tell me what expression I can us in order to support those
3 methods at once ?

Thanks,

Ori.

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: joemono | last post by:
Hello everyone! First, I appologize if this posting isn't proper "netiquette" for this group. I've been working with perl for almost 2 years now. However, my regular expression knowledge is...
13
by: Eddie | last post by:
I need to validate a text input field. I just want to say if user enters 93101 or 93102 or 93103 or 93105 or 93106 or 93107 or 93108 or 93109 or 93110 or 93111 or 93116 or 93117 or 93118 or...
0
by: Brian Davis | last post by:
The problem is in the word boundary \b. A leading "(" will match as a word boundary before it gets to the test for a "(". Changing the expression to: (?n)(\b|\()1??\(?(?<areaCode>\d\d)?\)??(?...
2
by: PawelR | last post by:
Hello everybody, I have problem with regular expression. I want "code" telephon number and I have two types number: 1) or 2) ( or ) where x - is digital Maybe someone know where is simple...
7
by: Chris Kennedy | last post by:
Does anyone know a regular expression that will validate the file extension but also allow multiple file extensions if necessary. It also needs to be case insensitive. Basically, what I want is to...
2
by: Neo Geshel | last post by:
Greetings, I have a form with a telephone field. It is very specific, as it has four text boxes - the country code, area code, prefix and suffix. I can validate each of them individually, but...
5
by: Ganesh | last post by:
Hi There, I need to validate email address with regular expression control, i tried something like this ^+*@*\.*$ but i need to validate even if it is blank, it should say invalid email,...
5
by: shapper | last post by:
Hello, What is the Regex expression to validate a date time format as follows: dd-mm-yyyy hh:mm:ss An example: 20-10-2008 10:32:45
5
by: Abhishek | last post by:
Hi this is my another validator in javascript to validate the Phone Number :-) <script language='javascript'> function funcCheckPhoneNumber(ctrtxtMobile,e){ if(window.event){ var strkeyIE =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.