2

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?

1 Answer 1

7

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.
Sign up to request clarification or add additional context in comments.

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.