Paul Tanné
Paul Tanné

Reputation: 77

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)?

Upvotes: 0

Views: 42

Answers (2)

user5334821
user5334821

Reputation:

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

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

Upvotes: 0

Hugo
Hugo

Reputation: 61

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

Upvotes: 1

Related Questions