.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
satyapriyanayak
Subhransu Sekhar Jena
abhays
SP
DotnetUser
Post New Web Links

Regular Expression For US Phone Number in C#?

Posted By:      Posted Date: November 16, 2010    Points: 0   Category :.NET Framework
 
Hello friends,

If you know regular expression for US phone validation please let me know. I have used

^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$  expression . But it is fine for 10 digit numbers validation. I may have 12 digit numbers like 23-456-213-765  .  What is the regular expression for this?




View Complete Post


More Related Resource Links

Regular Expression for Canonical address format for phone numbers?

  
The canonical address format is a universal (international) phone number format and it's pattern is as following:

Pattern:
+ Country/RegionCode (AreaCode)SubscriberNumber

Example:
+1 (425) 555-0100

I need a regular expression that supports this?

Regular Expression Validator error for masked SSN number

  

Hi all,


I need a small help.
Below given is the ASP.NET Regular Expression Validator that i am using to validate the SSN number being used in my project.


<asp:textbox id="txtSSN" runat="server"  size="14" onBlur="javascript:return mask(this.value,this,'3,6','-','Pri');" maxlength="9" AutoCompleteType="Disabled"></asp:textbox>

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="<span style='display:none'></span><img src='../images/arrow.gif' alt='Enter a valid 9 digit SSN number'>" ControlToValidate="txtSSN" ValidationExpression="^[0-9X]{3}[\- ]?[0-9X]{2}[\- ]?[0-9]{4}$"></asp:RegularExpressionValidator>



In this project the SSN number is masked before being displayed to the user.
Below given is the format for the display of the SSN number in the front end code

SSN NUMBER in the code behind            :     333-44-2222
SSN NUMBER displayed in textbox as    :     XXX-XX-2222

 


Regular expression to split number

  


I am splitting the phone number entered into two parts using regular expressions below


(^\d{3}) - last 7 digits


\d{7}\b - first 3 digits


This works fine if entered value is 1234567890 or 123-456-7890


and fails if value entered is 123 456 7890 (with spaces) or 123.456.7890


how to modify above expressions to trim (spaces and .)?


Thanks


Regular Expression needed for 10, 11, or 12-digit number in code behind

  

Hi there,

I am in need of validating a number that can be 10, 11, or 12 digits in lenght.  It cannont contain any spaces, symbols, or letters.  I have to do this in the code behind of my web form.  I am using C# ASP .NET 2.0. 


Security Briefs: Regular Expression Denial of Service Attacks and Defenses

  

Microsoft security expert Bryan Sullivan believes denial-of-service blackmail attacks will become more common as privilege escalation attacks become more difficult to execute. He demonstrates how to protect your apps against regular expression DoS threats.

Bryan Sullivan

MSDN Magazine May 2010


Help with regular expression

  

Hello,
I am using this regular expression: /.*-lyrics-.*$

and I need the expression find urls like this:
http://domain.com/lor-mbongo-lyrics-loboko-txphzzf

and it do really does that!

The problem is that it finds also this URL:
http://domain.com/lost-lyrics-5mk4f/lyrics

Whar regular expression should I use to exclude urls that end with /lyrics ?

Thanks :]

 

 


Regular Expression to Match
in HTML

  

Here is the kind of text I want to match via a regular Expression

The id="dgSchedule" is always present in the TAG but its location may differ

The table is span over multiple line/contains white spaces/tabs...

I have the regular expression to match the start and end tag respectively over a single line

\<table .*\>

\</table\>

The problem is to match the whole table span over multiple lines

<table cellspacing="0" rules="all" border="1" id="dgSchedule" style="border-style:None;height:100%;width:100%;border-collapse:collapse;">
	<tr class="blackbar" align="center" style="background-color:#7FB4DE;font-family:Verdana;font-weight:bold;height:20px;">
		<td>From Place</td><td>To Place</td><td>Time</td><td>Bus Type</td>

	</tr><tr style="background-color:#DEECF5;">
		<td>1</td><td>2</td><td>00:15</td><td>Express</td>
	</tr><tr style="background-color:#EFF5FA;">
		<td>2</td><td>3</td><td>00:15</td><td>Express</td>
	</tr><tr style="background-color:#DEECF5;">

		<td>3</td

Need a regular expression

  

I have a required field validator for a texbox, but I just found out that the texbox can have a space in it (for a delimiter, let's say).

I checked the .net and regexlib.com, but couldn't find what I was looking for.

I simply need a regular expression that basically excepts any character string including spaces in it or even a space by itself

Can someone help me out?


regular expression

  
hi...can anobody help me that how to write regular expression for textbox..such as the textbox should accept only numbers otherwise alert msg should be displayed ..displaying that u cannot enter the charcter in the textbox..i want this in javascritp.. 

Getting IMEI number of a mobile phone

  
I am developing an  asp.net web application which supplies content to mobile phones  , Im trying to get the imei number of  mobile phones using thier numbers. How can we achieve this?

Matching set of characters via regular expression

  
I need to be able to match sets of quote and space characters in a string and replace these accordingly. I currently have this done in 2 lines of code, but would like to use regular expression so that I can use only 1 line of code. See below: var Qt = unescape("%22"); //quote char var Sp = unescape("%20"); //space var Cr = unescape("%0d"); //carriage return var Lf = unescape("%0a"); //line feed var CrLf = Cr + Lf;  //carriage return & line feed stringOut = stringIn.replace(Qt+Qt+Sp+Qt,Qt+Qt+CrLf+Qt); stringOut = stringOut.replace(Qt+Qt+Sp+Qt+Qt,Qt+Qt+CrLf+Qt+Qt);   I want to replace space in string like in pattern below with carriage return line feed: (in hex) 22 22 20 22 or 22 22 20 22 22. This needs to return 22 22 0D 0A 22 or 22 22 0D 0A 22 22   Line in green above will only match and replace 22 22 20 22 , but I want have regular expression into 1 line of code which  will match and replace either 22 22 20 22 or 22 22 20 22 22  

Regular Expression for Digits, comma & space combination

  
Hi Can you suggest a Regular Expression for the following category. A text box which should contain: Max size : 53 0-9 digits + a comma + a space The 0-9 numbers should be repeated 5 times and separated by a comma and a space Eg: 123456789, 123456789, 123456789, 123456789, 123456789 Thanks, David.      

Need Regular Expression for d/mm/yyyy hh:mm:ss

  
Hi everybody,i am stuck in generating a regular expresion for this typem/dd/yyyy hh:mm:ssbecause i am dealing with some date values, for example i have  date values like bellow, 3/29/2007 13:28:343/27/2007 17:12:36so i need to find out a regular expression type in order to validate this, i already got some regular expression string like this ,^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)[0-9]{2}$but this is working only for 03/29/2007but if i use 3/29/2007 it wont work , or if use 03/27/2007 17:12:36 still it wont work so i really need you guys help on this to generate my regular expression string thanksregrdssukavi

need regular expression to get message body

  
I have text like this: <tr class="NormalRow_Small"> <td colspan=2>&nbsp;</td> <td colspan=3> </td> </tr> <tr class="NormalRow_Small"> <!--description--> <td colspan="5"> <font size="2">Hi All,<div><!br /></div><div>I'm glad to introduce ...</div><div><!br /></div><div>Actually we already have ... <font size=1>(see link for full text)</font></font><br> <font size="1"> </td> </tr> <tr> <td colspan=5><hr /></td> </tr>   I want to get bold text, please help me.   Thanks, Alex.
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend