TrueWill TrueWill - 6 months ago 15
Javascript Question

Validation only firing on submit for additional methods

By default, jQuery Validate validates on keyup and blur. This does not work for custom validations added with

addMethod
, including all of those in the included additional-methods.js script.

Example plunk

In the above example email will validate on keyup but phone (
phoneUS
) will only validate on submit.

How can I make additional methods work exactly like built-in methods?

Answer

How can I make additional methods work exactly like built-in methods?

They already do.

The problem is within your Plunker:

<input type="phoneUS" name="phone">

You have not properly defined the phoneUS rule anyplace, because type="phoneUS" is not a valid element type.

You could use type, class, or an HTML5 validation attribute to define the jQuery Validate rules inline. However in this case, since there is no such type or HTML5 attribute named "phoneUS", only class will properly work inline...

<input type="text" class="phoneUS" name="phone">

DEMO: http://jsfiddle.net/w145puuz/