user1321553
user1321553

Reputation:

Regular Expression to match specific string

RegEx has always been my Achilles' heel. I am writing web app, where user will input his identifier. I'm using RegexValidator to validate this input.

The identifier should be something like this:

TN-In-PL-KW-2012-1234

And this is how the identifier is built:

Please help me writing RegEx to match this identifier.

Upvotes: 7

Views: 16720

Answers (3)

jorgehmv
jorgehmv

Reputation: 3713

^TN-(In|Te|Yo|Et)-[A-Z]{2}-[A-Z]{2}-\d{4}-\d{1,4}$

Just as a comment, I recommend you Rubular if you want to improve your regex skills, it's a simple and practical page to have in mind when you need to work with regex

Upvotes: 7

phatfingers
phatfingers

Reputation: 10250

TN-(In|Te|Yo|Et)-([A-Z]{2}-){2}(19[7-9][0-9]|200[0-9]|201[0-2])-[0-9]{1,4}

Upvotes: 2

burning_LEGION
burning_LEGION

Reputation: 13450

TN-((In)|(Te)|(Yo)|(Et))-[A-Z]{2}-[A-Z]{2}-\d{4}-\d{1,4}

Upvotes: 1

Related Questions