danday74 danday74 - 1 year ago 169
jQuery Question

What is the jquery alternative for checkValidity()

I've just discovered the JavaScript Validation API checkValidity() function

See http://www.w3schools.com/js/js_validation_api.asp

caniuse.com says this API is available in Firefox and Chrome (I DO NOT need support for other browsers).

Does anyone know whether jQuery provides its own implementation of this API - many thanks :)

Answer Source

Wanting something from Javascript for jQuery? Just add it to the jQuery namespace like so:

$.fn.isValid = function(){
  return this[0].checkValidity()

Then you can just use $("#id").isValid() to return either true/false depending on the validity.

Credit to @Andrew Whitaker.