JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.13.1/jquery.validate.js"></script>
<form id="myForm" method="post">
<input name="myelement" id="myelement" value="">
</form>
<button id="testit">testit</button>
JavaScript
var validator = $("#myForm").validate({
rules: {
myelement: {
minlength: 2,
maxlength: 4,
required: true,
remote: {
url: "/echo/html/",
type: "POST",
data: {
html: 0,
delay: .5
}
}
}
},
messages: {
myelement: {
remote: "error message"
}
}
});
$('#testit').click(function () {
if ($('#myelement').valid()) {
$.post("/echo/html/", {
html: 0,
delay: .5
}, function (status) {
if(!+status){alert('failed remote validation');}
});
}
else {alert('failed normal validation if first attempt, otherwise could be either.');}
})