0

I'm programming a little HTML form with pattern included in a tag where a phone number must be introduced. Problem is I can't make the pattern to work as intended. Even if the desired pattern is introduced it still won't let submit the form. It's pretty obvious there's a problem in the pattern but can't figure out what (seems OK to me, but I'm no good with patterns).

The format to be accepted is XXX-XXXXXX, with X being numbers. Here's the code in that <input> tag so far:

<input type="text" name="phonenum" id="phonenum" maxlength="10" pattern="/^\d{3}-\d{6}$/" required="required">

Same pattern is working in an alternate JavaScript validation file. I don't know what must be changed for it to work as a tag pattern.

3 Answers 3

1

You don't need to put the / / marks. Something like

<input type="text" name="phonenum" id="phonenum" maxlength="10" pattern="\d{3}[\-]\d{6}" required="required">

Should work

Sign up to request clarification or add additional context in comments.

Comments

0

Try this pattern:

pattern="[0-9]{3}-[0-9]{6}"

Comments

0
 <input type="text" name="phonenum" id="phonenum" maxlength="10" pattern="^\d{3}-\d{6}$">

You don't need delimiters, that's all...tested in FF.

1 Comment

It was THAT easy! Still don't get why I have seen it with delimiters in more than one place, but i'll try to remember not to add them. Many thanks!

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.