Reputation: 1
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.
Upvotes: 0
Views: 55
Reputation: 11328
<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.
Upvotes: 0
Reputation: 286
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
Upvotes: 1