JSFiddle - React, Tailwind, and code Playground
HTML
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.js"></script>
<form>
<input type="text" name="pickUpLocation">
<input type="submit">
</form>
JavaScript
jQuery.validator.addMethod('aRule', function (value, element) {
var optional = this.optional(element);
return optional || true;
}, '');
jQuery.validator.addMethod('ajaxRule', function (value, element) {
var optional = this.optional(element);
$.getJSON('http://api.github.com/rate_limit', function (response) {
console.log(response.toString().length);
return optional || true;
});
}, '');
$('form').validate({
debug: true,
rules: {
pickUpLocation: {
required: true,
aRule: true,
ajaxRule: true,
},
},
messages: {
pickUpLocation: {
aRule: "FaiL! Rule",
ajaxRule: "FaiL! AJAX rule"
}
}
});