1

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.

1
  • If you willing to spend a bit, RegExBuddy is great for allowing mere mortals to write regex's Commented Sep 4, 2011 at 8:37

3 Answers 3

5

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

Sign up to request clarification or add additional context in comments.

2 Comments

@Sachira Be aware that that Regex will match non-euroamerican digits, like BENGALI DIGIT ZERO (the ০ is your digit :-) ). In fact, it will match any character from Number, Decimal Digit (found here NSRegularExpression_Class, read under \d).
@Cat++ ah..is there any way to avoid such confusion?in my problem, given format is National Identity Card number which only use in my contry. So, to my application, there will not be much confusion, but to my future knowledge, it'll help me a lot. :) thanx again.
2

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

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

Comments

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.