How to check if a browser has built-in HTML5 form validation ability? By doing so, we don't need to apply jQuery form validation functions on browsers who can validate form by themselves.
[Solved] Based on ThinkingStiff's answer, here is a way:
if (typeof document.createElement("input").checkValidity == "function") { alert("Your browser has built-in form validation!"); }
Using HTML5, we can create a form with built in validation (i.e. no javascript required). Earlier, we were using JAVASCRIPT to control form validation.
Using the email type, we can check the validity of the form field with a javascript function called… checkValidity() . This function returns a true|false value. checkValidity() will look at the input type as well as if the required attribute was set and any pattern="" tag .
With HTML5, form validation is a built-in feature. There are various validation attributes that come with HTML5. When form input is valid, the :valid CSS pseudoclass is applied to the element. If it's invalid, then the :invalid CSS pseudoclass is applied to the element.
The simplest HTML validation feature is the required attribute.
Simply check if the checkValidity()
function exists:
Demo: http://jsfiddle.net/ThinkingStiff/cmSJw/
function hasFormValidation() { return (typeof document.createElement( 'input' ).checkValidity == 'function'); };
Call it like this:
if( hasFormValidation() ) { //HTML5 Form Validation supported };
You can do this using Modernizr javascript http://www.modernizr.com/ . You can take help from this post html5 form validation modernizr safari . You can also take advantage of modernizr load
The basic syntax for Modernizr.load() is to pass it an object with the following properties:
Both yep and nope are optional, as long as you supply one of them.
To load and execute the script in check_required.js, add the following block after modernizr.adc.js has been attached to the page (the code is in required_load.html):
<script> Modernizr.load({ test: Modernizr.input.required, nope: 'js/check_required.js', complete: function() { init(); } }); </script>
Source : http://www.adobe.com/devnet/dreamweaver/articles/using-modernizr.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With