JSFiddle - React, Tailwind, and code Playground

by Prakash Thete

HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.15.0/jquery.validate.js"></script>
<div>
  <form id='example-form'>
    <input type='text' id='address' name='address'>
    <input type='submit' value='Submit'>
  </form>
</div>

JavaScript

function validateForm() {

  $.validator.addMethod("exampleword", function(value, element, string) {
        return value.indexOf(string) > -1 ;
    }, $.validator.format("Please enter '{0}'"));

    $("#example-form").validate({
     rules: {
       address: {
         required: true,
         exampleword: "Foo"
       }
     },
     messages: {
       address: {
         required: "Please enter an address",
         exampleword: "Please include Foo"
       }
     },

      submitHandler: function (form) {
          console.log("Validated Ok");
           return false;
      }
	  });
}

$(document).ready(function(){
	validateForm();
});