How can I test the field client side with HTML5 read only?

I have an input field that launches a datepicker. To make this work on a mobile device, I made a read-only field. This means I can start the date picker on click (or touch) with jQuery, and the tap does not open the keyboard on the mobile device.

However - the attribute readonly

bypasses HTML5 validation mechanisms. Can I add something that then either mimics the look and feel of HTML5 validation in order to maintain consistency, or that forces HTML5 validation despite being a field readonly

?

Edit . I am looking for confirmation that the field is filled in (required) and it is desirable that it conforms to a specific date format.

+3


source to share


2 answers


readonly

fields cannot have an attribute required

, as a rule, they will already contain some value.



Have a look at Standard HTML5 Drafts

0


source


Try looking for the 'pattern' attribute.

For dates, this template might come in handy:



^\d{4}\-\d{1,2}\-\d{1,2}$|^\d{1,2}\/\d{1,2}\/\d{4}$

      

0


source







All Articles