In some cases, using HTML5 validation will fail if an input type used is not supported in that browser; this is the time when we need to revert to using JavaScript, or in this case jQuery. For example, date as an input type is not supported in IE11, as shown here:
<input type="date" name="dob"/>
This is how the preceding code will be rendered:
<input type="text" name="dob"/>
The trouble is that with the type falling back to text, browsers will not correctly validate the field. To get around this, we can implement a check using jQuery—we can then start adding some basic validation using jQuery, which will override the existing native HTML checks made in the browser.
Let's take a look at how we can achieve some of this in practice, with a simple demo, as follows:
Open up a copy of
basicform.html
from the code download that accompanies this book.In the
<head>
section, add a link to jQuery along with a link to your validation script:<script src...