2

a textBox can contain values in format

DL-06-T-7405 (first two Alphabets then two Numbers then Alphabet and next four are Numbers) or DL-06-TT-7405(first two Alphabets then two Numbers then two Alphabet and next four are Numbers) or DL-06-TTT-7405(first two Alphabets then two Numbers then three Alphabet and next four are Numbers)

what i have done so far..

/^[A-Z]{2}[0-9]{2}\w$/

but i can not make other cases case 1: DL-06-TTT-7405 case 2: DL-06-TT-7405 case 3: DL-06-T-7405

how can i allow a textbox takeabove 3 cases only not other than this

1
  • You're missing the - characters in your Regex Commented Nov 3, 2016 at 8:59

1 Answer 1

1

You may use a limiting quantifier {1,3} to match 1 to 3 occurrences, and add hyphens in between subpatterns:

^[A-Z]{2}-[0-9]{2}-[A-Z]{1,3}-[0-9]{4}$
                        ^^^^ 

See the regex demo

Pattern details:

  • ^ - start of string
  • [A-Z]{2} - 2 uppercase ASCII letters
  • - - a literal hyphen
  • [0-9]{2} - 2 digits
  • - - - hyphen
  • [A-Z]{1,3} - 1 to 3 uppercase ASCII letters
  • -[0-9]{4} - a hyphen, 4 digits
  • $ - end of string.
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.