can we join 2 HTML pattern in one input?

I have this pattern in HTML for an ID login :

[0-9]{6} (need 6 numbers)

and i just learned some users have a letter before numbers so it became :

^(a|A)([0-9]{6})$

and i want to know if it's possible to join the two pattern in one (write 6number or 1 letter + 6 numbers)?

2 answers

  • answered 2018-05-16 06:39 Hugo

    Yes, you can join the two patterns with the "|" character. Please, try this: [a-z]{1}\d{6}|[A-Z]{1}\d{6}

  • answered 2018-05-16 06:41 Michael Townshend

    ^(a|A)?([0-9]{6})$

    By adding the ? we are saying the first capturing group must appear either zero or one time.