.NET Framework Bookmark and Share   
 index > Regular Expressions > validate a asp:textbox which starts with alphabet "T" followed by numbers
 

validate a asp:textbox which starts with alphabet "T" followed by numbers

How can I validate a asp:textbox which starts with alphabet "T" followed by numbers.Please help
Learner01
T\d*

gives the Capital T followed by zero or more numbers

T\d+

Same as above but will fail unless there is one number. + is 1 or more while * is zero or more.
William Wegerson (www.OmegaCoder.Com)
OmegaMan
Thank you for your reply , but when I try to run that regular expression , it gives me unrecognised escape sequence builderror.
Can you help me on this.I am trying to enter "T12345" kind of value inside the textbox andd trying to validate the same.
My code is :

<asp:TextBox id="txt1" runat="server"/>
<asp:label id="" runat="server"/> and I am using

using

System.Text.RegularExpressions;


on button click

if

(!Regex.IsMatch(txt1.Text,"T\d+"))

{

lblmsg.Text="Error";

}

Build Error:unrecognised escape sequence error.

Learner01
@"T\d+"
William Wegerson (www.OmegaCoder.Com)
OmegaMan
Thanks, that helped alot but doesnot completely solve my purpose.Is there anything that allows only numbers(0-9) after "T" and no characters or alphabets after that.Because the above also allows alphabets after numbers again.

example:T1234asdf [this is validating this as valid input]

I want like this :T1234 (only numbers and not alphabets after numbers).

Learner01

Just add boundary checking to Omega's pattern

^T\d+$


www.wonderstudio.cn
Eping Wang

You can use google to search for other answers

Custom Search

More Threads

• Replacing <img ... sources with regEx?
• regular expression to replace hyperlink
• A shot across the bow (Would like some help)
• String boundary or numeric boundary in Regular Expressions
• Need Help With Simple RegEx
• RegularExpressions.Regex.IsMatch
• Regular Expression for HTML Tags into TreeView
• Extracting a the matched pattern for a string
• [VS IDE] Expression for all quotes from solution
• Help me with regular expression