SachiraChin
SachiraChin

Reputation: 570

Validate certain string using RegEx

I need to validate following string using Regular Expressions. These are the constraints which apply for this string.

  1. From beggining it has 9 numbers.
  2. In the end it has character 'V' or 'X'. They can be simple or capital.
  3. Whole length of string must be 10.

Ex: 84256142V, 547812375X

Can anyone provide me RegEx for validate this.

Upvotes: 1

Views: 131

Answers (3)

casraf
casraf

Reputation: 21694

This is the Regex you need: /^(\d){9}(V|X)$/i

Upvotes: 2

Luke Girvin
Luke Girvin

Reputation: 13442

Depends on the language, but it will be something like this:

^[0-9]{9}[VvXx]$

Upvotes: 2

Cat Plus Plus
Cat Plus Plus

Reputation: 129894

^\d{9}[VX]$ if you put the regex engine in case-insensitive mode, ^\d{9}[vVxX]$ otherwise.

Upvotes: 5

Related Questions