lakshganga
lakshganga

Reputation: 2465

Regular expression to restrict characters to 6

I need a regular expression to validate the text in a particular format Eg: VT-ABC

This particular regular expression should start with VT- followed by 3 alphabet letters. The whole string should contain exactly 6 characters.

I tried the regular expression ^[V][T][-][A-Z]{6}, but this is not working.

Any guidance would be appreciated.

Upvotes: 1

Views: 598

Answers (1)

Tim Pietzcker
Tim Pietzcker

Reputation: 336118

You need an end-of-string anchor, and of course only three letters should be allowed, not six:

^VT-[A-Z]{3}$

Upvotes: 7

Related Questions