html5 input pattern simple question

Dear Experts,

I need an input html5 pattern that only accepts 7 numbers, and the number must start with 1 or 2

I wrote below pattern but one thing is missing. How can I control if the number is started with 1 or 2? Thank you

<input type="text" name="agent" id="agent"  pattern="[0-9]{7}" title="it must be 7 numbers. Need to start with 1 or 2" required autofocus>

Open in new window

LVL 1
BRMarketingAsked:
Who is Participating?
 
Ryan ChongCommented:
try:

<input type="text" name="agent" id="agent"  pattern="^[1-2][0-9]{6}" title="it must be 7 numbers. Need to start with 1 or 2" required autofocus maxlength="7">

Open in new window

1
 
BRMarketingAuthor Commented:
thank you so much
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.