Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
I am facing a problem in validation of id card number. Here it is sample
03483-6890375-7 means firstly 5 digit then - then again 7 digits - and at the end again 1 digit.
Please help me... so if someone enters the wrong number in the textbox, then it should show the message "sorry enter valid no."
Posted
Updated 19-Jun-11 15:48pm
v3

The regular expression to use is \d{5}-\d{7}-\d{1}

You can use the Regex class in the System.Text.RegularExpressions to check whether your text matches the regular expression.

System.Text.RegularExpressions.Regex.IsMatch("Your Text", @"\d{5}-\d{7}-\d{1}", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
 
Share this answer
 
Comments
Monjurul Habib 19-Jun-11 19:00pm    
nice answer. my 5. please look at my one.
sunnyaliraza 20-Jun-11 0:50am    
thanks g i think its looking pretty well but i have another problem because i m begnner and do not know where to use it mean on button coding or in the textbox event please help me.......i am using a text box for number......so what should i do regarding this??
If you learn regular expression things then it will be easy for you here after.

http://www.regular-expressions.info/[^] - Which contains tutorials, tools, examples, books & references.

http://www.regxlib.com/[^] - Massive library contains many examples
 
Share this answer
 
Comments
Kim Togo 20-Jun-11 2:39am    
Good answer my 5.
OP: Download this little tool: http://www.ultrapico.com/Expresso.htm
thatraja 20-Jun-11 3:01am    
Yeah, Also I found that in Free Tools forum, check it for more softwares. Thanks Kim.
If you are using Asp.net Validation Controls, then use the RegularExpressionValidator so that the validation can be done on the single click on same time.

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="RegularExpressionValidator" ControlToValidate="TextBox1" ValidationExpression="\d{5}-\d{7}-\d{1}"> </asp:RegularExpressionValidator> 
 
Share this answer
 
Hope Validation with Regular Expressions Made Simple[^] article from CP might help you.
 
Share this answer
 
Read this The 30 Minute Regex Tutorial[^].
It helps, really.
 
Share this answer
 

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