Re: phone number regular expression problem
- From: "Mythran" <kip_potter@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 31 May 2006 08:46:01 -0700
<mrshrinkray@xxxxxxxxxxxxxx> wrote in message news:1149083237.738040.303340@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
^(\+{0,1}[0-9\-]*)
seems to work for me, I tried it with:
+44-444-2342342
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
There are some awesome phone number examples out there....I am sure you can find one that matches most phone numbers in most regions :)...but darn, that has to be a HUGE pattern :P
Here's one that does U.S. and regional telephone numbers ... including extentions (copied and slightly modified from http://javascript.about.com/library/blre.htm).
----
/// <summary>
/// Determines whether the specified text is a valid phone number.
/// </summary>
/// <param name="Text">The text to check.</param>
/// <returns>
/// Returns <see langword="true" /> if the <paramref name="Text" />
/// argument is a valid phone number, otherwise returns <see
/// langword="false" />.
/// </returns>
private static bool IsPhoneNumber(string Text)
{
const string PHONE_PATTERN =
@"^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,3})|(\(?\d{2,3}\)?))" +
@"(-| )?(\d{3,4})(-| )?(\d{4})(\s*(x|ext)\d{1,5}){0,1}$";
return System.Text.RegularExpressions.Regex.IsMatch(
Text,
PHONE_PATTERN
);
}
----
HTH,
Mythran
.
- References:
- Re: phone number regular expression problem
- From: mrshrinkray@xxxxxxxxxxxxxx
- Re: phone number regular expression problem
- Prev by Date: Re: What's happended to ANSI chars 135 and 130 - ToString/GetBytes
- Next by Date: Re: Unblock NetworkStream.Read from another Thread?
- Previous by thread: Re: phone number regular expression problem
- Next by thread: Can anyone tell me of any optimations I could do to this to make it faster?
- Index(es):