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

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

ASP.Net Regular Expressions

Posted By:      Posted Date: October 22, 2010    Points: 0   Category :ASP.Net
Hi Friends.

I need your help, i've searched, a lot of tutorials, and found none that had one answer for me.

I'm using the regular expression validators to secure my web page. But i don't know how is the expressions that do this two things:

- a textbox containing only numbers, with no spaces.
- a textbox containing only letters [a-zA-Z], with spaces and no limit to the word count

Can you help me please?

Thank you very much.

View Complete Post

More Related Resource Links

Toolbox: Online Scheduling, Jeff Smith's SQL Blog, Easy Regular Expressions, And More


This month Scott looks at improving development skills, writing regular expressions, a web scheduling control and a SQL tips blog.

Scott Mitchell

MSDN Magazine November 2008

SQL Server 2005: Regular Expressions Make Pattern Matching And Data Extraction Easier


Now you can perform efficient, sophisticated text analysis using regular expressions in SQL Server 2005.

David Banister

MSDN Magazine February 2007

Toolbox: Rich Web App UIs, Tools for Regular Expressions, and More


In this issue, create rich Web app UIs, explore tools for regular expressions, and create screen mockups.

Scott Mitchell

MSDN Magazine February 2007

Netting C++: Introducing Regular Expressions


This month Stanley Lippman introduces the support for regular expressions in the .NET Framework.

Stanley B. Lippman

MSDN Magazine November 2006

C++ at Work: Form Validation with Regular Expressions in MFC


I thought I'd use this month's column to describe an interesting app I built using the RegexWrap library described in my article "Wrappers: Use Our ManWrap Library to Get the Best of . NET in Native C++ Code" in this issue.

Paul DiLascia

MSDN Magazine April 2005

Regular Expressions in Filterd Textbox Extender.

Hi... Can we use Regular Expression in Filterd Textbox Extender to match Valid or invalid char. If yes how? Please give me a simplle example... Thank you?

How to get a non-closed tag with regular expressions

Use regular expression to filter following html fragment:<html><img href="***"><b><img href="***" /></html>Expected match result:<img href="***"><b>How to write the pattern? thanks in advance!

Combining email and numeric regular expressions

Hi, I am using the following regular expression within an XSD to validate a combination of email ID's and six digit employee ID's separated by a semicolon (;). for example : vedansh.mm@fgfgfg.com;ghgh@ff.com;333333;555555 ^((\s*;?\s*[0-9a-zA-Z_]([-.\w]*[0-9a-zA-Z_])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})+\s*(;\d{6})*)*$ It works for the following vedansh.mm@fgfgfg.com;ghgh@ff.com;333333;555555 but does not work when the six digit number preceeds the email, like below 222333;vedansh.mm@ct.com;ghgh@ff.com;333333;555555;fhfhf@gggg.com or if the input contains only numbers, like 555555 What am I doing wrong. The numbers and email address count may or may not be the same. Thank you for all your help Vedanshu

Visual Studio 200X (IDE) - Regular Expressions

The regular expressions in Visual Studio 2003/2005/2008 are not the same as .Net Regular Expressions found in code. For that resources check out Regular Expression Resource. If you are reading this you no doubt have questions about Visual Studio's version of Regular Expressions which is totally different from .Net Regular Expressions or any other flavor.The differences between .Net and Studio's version are best summed up here by Jeff Atwood's Coding Horror: Visual Studio IDE and Regular Expression.Of course to do any search or replacing, one will need to use the syntax. That is provided here Regular Expressions Visual Studio.Here are two examples and notes to do a search and replace that I have in my notes which I will share with you. I ran into a situation where I had to refactor text within a few documents. I had never used the Regular expressions in studio during search and replace and decided to learn something new. I had in the text files text that had a pattern like this: return data["COVERAGE_ELECT"] and needed to change each similar occurance to this: return ProcessDataString("COVERAGE_ELECT");Here is the search text I created which specified that the quoted string would be saved into a Visual Studio set (as seen in the {} ) which would create a match that would later be accessed in the replacement text by the Visual Studio replace \1: Visual

Construct Regular Expressions

Hi ,  I need to construct a regular expression for the password textbox which shouldn't accept special characters($,@,!,etc).Even whitespaces,tabs. I tried the below this accepts special characters. Any inputs <asp:RegularExpressionValidator ID="RegEx" runat="server" ControlToValidate="Password" ErrorMessage="Password must be atleast 8 characters and include a number,alphabets upper case and lower case. "ToolTip="Password format is not correct" ValidationExpression="^(?=.{8})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$"> </asp:RegularExpressionValidator>    Regards  Janet

Maxlength & Regular Expressions for text boxes


So over here, I'd asked about Regex and methods of limiting user input in text boxes, and got some very good answers, but I've hit another snag.

1) Using "Maxlength=XXXX" works great for single-line text boxes, but doesn't prevent the user entering too much text in multi-line text boxes. I wouldn't mind that, but it also doesn't trigger an error to display to the user, it just doesn't let the page submit.

2) So I've been using Regular Expressions (i.e, .{0,50} ) to pop up an error message when the user enters too much text. However, there's again a problem with multi-line text boxes. Using the dot for the validation expression does not allow the user to enter line breaks. Using \r\n will allow line breaks, but that's it. I keep looking at RegEx references online, and I can't find a way to allow both. Any combination or \r\n and . that I've tried has resulted in the expression allowing only line breaks.

So my question is this - what Regular Expression should I use to allow text (any character) with line breaks? Or, is there a better/simpler way to handle this?

 Thanks a million!


How to convert .html format data to normal text using Regular Expressions?

How to convert .html format data to normal text using Regular Expressions?

Have match AD path Regular Expressions?

Have match AD path Regular Expressions?

Combining two regular expressions


It's my first post here so hi everyone. I've developed regular expression which parses some data from a website (online dictionary). The only difference between them is semi-colon at the end of one expression, but both of them give me good results, so I'd like them to be one RegEx.

My expression:
"<a href=\"/slownik/polsko_angielski/.*\">(.+)</a>"


And a part of the exmaple code which I'm trying to get data from:

 <!-- google_ad_section_start -->


      <div class="znaczenie"><h3>W znaczeniu ogólnym</h3></div> 

     <div class="definicja"><span>&raquo;</span> <a href="/slownik/polsko_angielski/,sko%C5%84czy%C4%87+z+czym%C5%9B">skonczyc z czyms</a>; <a href="/slownik/polsko_angielski/,rzuci%C4%87+co%C5%9B">rzucic cos (jakies zajecie, prace)</a> 





     <div class="definicja"><span>&raquo;</span> <a href="/slownik/polsko_angielski/,zrezygnowa%C4%87">zrezygnowac</a>; <a href="/slownik/polsko_angielski/,rezygnowa%C4%87">rezygnowac</a

Find & Replace - Regular Expressions, what's wrong here?



Not really a huge concern, just a minor 'bout of "WTF?".

so [A-Z] matches any 1 character that is between capital a and capital z. 

[^A-Z] is matches any 1 character ths is NOT between captial a and captial z

\ is the escape character for matching literals.

CREATE TABLE X (col1 int, col2 nvarchar(15), test bit) ON primary

Find String:  {(\([^0-9]|,|\)[^,])}

REplace String: \1\n

However the \([^0-9] doesn't find anything in the string.  now frankly, (c seems to match the \([^0-9] because the first literal is a ( and the following character is NOT beween 0 and 9, yet the IDE says with the above set up, 2 matches.  Why? 

I proceed to try and do just "\([A_Z]" and just "\([0-9]" as the find string, and their correlated ^ versions and none of them detected any matches in the file containing that create table statement.  When I remove the \( from the string, it suddenly works.  what up with that?


Jaeden "Sifo Dyas" al'Raec Ruiner


"Never Trust a computer. Your brain is smarter than any micro-chip."
PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking

Create Regular Expressions from a string programmatically


I have a situation where users can set up masks for items such as phone numbers or postal codes.  Behind the scenes in the program the mask is applied to these data values as appropriate so they can be displayed in message boxes or labels.  So for example, a user can save a mask for a phone number to be (###) ###-####, or a Canandian postal mask of &#& #&3 (Example Toronto postal code M4B 1B3).  As you can see from the two masks that # represents numbers and & represents characters.  Is there a way programmatically (VB would be nice) that you can take a mask similar to these and turn it into a regular expression pattern so the mask can be applied to a value?


Lou Davis

How to match regular expression in c# with two grouped expressions

I would like to match a string separated by "/" followed by an expression like 1..100 and again string separated by "/" followed by 1..100, here is the string format.
here is my regular expression 
Regex regAppDH = new Regex(@"/String1/String2/String3/stirng4(\[[0-9]|[1-9][0-9]\])/string5/stirng6\[[0-9]|[1-9][0-9]\]")
This regular expression does not match after the first group expression ( before string5)  , can any body help to get this expression working.
stirng1,string2,string3,string4 and string5,string6 are alpha numeric and fixed. 

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