Closed
Bug 833693
Opened 13 years ago
Closed 13 years ago
empty string causes input pattern to incorrectly succeed
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: jmichae3, Unassigned)
Details
Attachments
(1 file)
|
944 bytes,
text/html
|
Details |
User Agent: Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0
Build ID: 20130116073211
Steps to reproduce:
created input element
<input type="number" pattern="^[1-3]$" id="number" onchange="doit()" onkeyup="doit()">
Actual results:
when input box was empty,did not show box with red highlight. regex pattern match was INCORRECTLY HANDLED for empty string.
Expected results:
should have shown an error condition (red highlight for number type input) for single digit in range 1-3.
Updated•13 years ago
|
Attachment #705248 -
Attachment mime type: text/plain → text/html
Updated•13 years ago
|
Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core
Comment 1•13 years ago
|
||
Mounir?
Comment 2•13 years ago
|
||
Thank you for this report Jim.
Unfortunately, it seems that the element is valid in the case you are mentioning as specified in the HTML specifications [1]. If the element's value is empty, the pattern does not apply. Actually, generally speaking, unless the required attribute is set, an empty value is never invalid. You can try the following code in different browsers: the behaviour should be consistent across all browsers supporting HTML5 Forms: data:text/html,<script>var i = document.createElement('input'); i.pattern="[1-3]"; alert(i.validity.valid);</script>
To solve your problem, I would recommend you to use the required attribute on your element.
[1] http://www.whatwg.org/specs/web-apps/current-work/multipage/common-input-element-attributes.html#attr-input-pattern.
Status: UNCONFIRMED → RESOLVED
Closed: 13 years ago
Resolution: --- → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•