473,769 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Phone number regular expressions

Hi,
I have a different requirement and it is :

I need to validate a phone number field.
It may or may not be a US phone number.

The constraints are :
*************** ********

# It should accept any number of numbers
# any number of - hyphens
# and one + symbol
# no other characters and alphabets are allowed

Thanks in advance

Venugopal.S

May 31 '06 #1
1 2126
First, in time like these, you should first check www.regexlib.com
which have a number of regex expression, free for the copying.

You may also want to try the "Regular Expression Workbench"
(http://www.gotdotnet.com/Community/U...-4EE2729D7322).
Also free, and how I wrote this.

But, this seemed simple enough to try myself -- with one exception:
# and one + symbol
I'm going to assume that it's only allowed as the first character:
^\+?[-\d]*$

^ (anchor to start of string)
+
? (zero or one time)
Any character in "-\d"
* (zero or more times)
$ (anchor to end of string)

venu wrote: Hi,
I have a different requirement and it is :

I need to validate a phone number field.
It may or may not be a US phone number.

The constraints are :
*************** ********

# It should accept any number of numbers
# any number of - hyphens
# and one + symbol
# no other characters and alphabets are allowed

Thanks in advance

Venugopal.S


May 31 '06 #2

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

Similar topics

5
19232
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 pretty limited. I wrote the following expression to take (hopefully) any _reasonable_ phone number input, and format it as (999) 999-9999 x 9999.
1
3075
by: Erik Jälevik | last post by:
I have a regular expression which I believe is correct but it's not behaving as expected. It is as follows: /\+?\d+*\d+/ The idea is that a phone number is allowed to be of the form: optional + followed by one or more digits followed by any combination of hyphens, spaces and digits followed by at least one digit. However, this regexp is letting through all sorts of expressions as long as
21
6254
by: AnnMarie | last post by:
<script language="JavaScript" type="text/javascript"> <!-- function validate(theForm) { var validity = true; // assume valid if(frmComments.name.value=='' && validity == true) { alert('Your full name is required. Please enter your full name!'); validity = false; frmComments.name.focus();
3
2442
by: Sansanee | last post by:
Hi, I am wondering if there is any format string for phone number. Just like those dd:mm:yyyy or C for currency. Can anyone enlighten me? Thank you in advance, Sunny
3
10033
by: deko | last post by:
I have a (Access 2003) contact management database where the user can double-click a contact's phone number in a form and have the Windows Phone Dialer dial the number. The problem is the number has to be in canonical format or dialing rules won't be applied (cf. MSKB Article 318575). I don't want to use an Input Mask because users like to put comments after the number, like: "985-983-0098 ext. 980 - Mike B." I thought there might be a...
5
3526
by: Kamaluokeakua | last post by:
I have to write an application that deals with clients in multiple countries. The addresses, phone numbers, country id and currency information has to be stored into a database that allows for the format of any country. I would like to be able to automatically display the information in the format of their country based on the information gathered from the Country field in the database. Is there any white paper, or book or site that has...
4
11737
by: Srinivas Kollipara | last post by:
Hey guys, i have a small question in C#. I have a windows form which has Address fields, zip code and phone number fields. it is working fine with U.S. but i need to modify that for all the other countries. is there any way i can validate zipcode and phone numbers.... Thanks in advance. bye Srinivas
2
4014
by: Ori | last post by:
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
2
1542
by: David C | last post by:
Is there a way to validate a specific phone# format on a control? I also want to be able to have the user enter an extension as part of the text. For example, the following would be valid. 123-456-7890 123-456-7890 x123 Below would be invalid. (123) 456-7890
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10222
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10050
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9999
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.