Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to validate text box that first two charactor allow string 'ES' and after that it allow int value such as 123456.

I want like this:-ES45612 or es45612
Posted
Updated 1-Oct-12 2:51am
v2

You can try following regex.

C#
string myCheck = "^[E][S]\\w*";
string myStr = "ES12121";
if(Regex.IsMatch(myStr,myCheck,RegexOptions.IgnoreCase))
{
    Console.WriteLine("Yes, it starts with ES");
}
else
{
    Console.WriteLine("No Its not!!");
}
Console.ReadKey();


Hope that helps. If it helps, mark the answer as solution.

Thanks
Milind
 
Share this answer
 
Comments
Raju2049 1-Oct-12 9:28am    
Actually friend I need solution in asp.net.
MT_ 1-Oct-12 9:30am    
<asp:RegularExpressionValidator ID="chk" runat="server"
ControlToValidate="txtBox"
ErrorMessage="First Two character must be ES!"
ValidationExpression="^[E][S]\w*" />

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900