Click here to Skip to main content
15,917,528 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
1.First five digits should be Numeric and next three will be alpha and last two will be numeric.

We need to validate a text field with the above condition,using the Regular expression.

What I have tried:

I was tried PAN based validation and did some changes for the same,but it didn't worked.
Posted
Updated 9-Jan-19 22:27pm

Please try this

^[1-9][0-9]{5}[a-zA-Z]{3}\d{2}
 
Share this answer
 
Comments
Patrice T 10-Jan-19 3:36am    
I fear your Regex starts with 6 digits.
Prasad Nikumbh 10-Jan-19 9:44am    
it is working fine you can test with regular expression debugger online.
In addition to solution 1 by Prasad Nikumbh[^] i'd recommend to start here: Regular Expression Examples[^]. There's a lot of examples, which may help you to understand how a regular expression work.

Another way to build and test regular expression is to install Expresso Regular Expression Tool[^].

Good luck!
 
Share this answer
 
Quote:
I was tried PAN based validation and did some changes for the same,but it didn't worked.

If you show your work, we can explain why it don't work.

Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
RegExr: Learn, Build, & Test RegEx[^]
Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx: Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
This site also show the Regex in a nice graph but can't test what match the RegEx: Regexper[^]
 
Share this answer
 
Thank you for all.

I was tried this and it is working perfectly.

[RegularExpression(@"^([0-9]){5}([a-zA-Z]){3}([0-9]){2}?$", ErrorMessage = "Entered CAN is Invalid")]


Ex : 12345ABC12
 
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