John Davison
John Davison

Reputation: 97

jquery input validation regular expression

I have an input which can accept a combination of data in this format:

dddd.nnnn

where d is an uppercase letter and n is a digit.

In some cases the initial uppercase letters could be 2, 3 or 4 in length. Then a . (point) can be entered, after which only numbers (0 - 9) can be entered.

Some sample entries are as follows

GHD.23
GH.235
EFF.1234

Can this be done by combining Regular Expressions?

Upvotes: 2

Views: 156

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174696

Your regex would be,

^[A-Z]{2,4}\.\d+$

DEMO

Explanation:

  • ^ Asserts that we are at the start.
  • [A-Z]{2,4} Allows 2 or 3 or 4 uppercase letters.
  • \. A literal dot.
  • \d+ One or more digits.
  • $ Asserts that we are at the end.

Upvotes: 7

Related Questions