JSFiddle - React, Tailwind, and code Playground

by alokswain

HTML

<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js"></script>
<form id="cartform">
    <lable for="amount"> Amount </label>
<input type='text' name='amount' id='<?php echo rand(0,99).$id; ?>' size='1' value='' class='required input_count' />
        <br />
        <button> Validate </button>
</form>

JavaScript

$(document).ready(function() {

    $.validator.addMethod('notmorethan', function(value, element) {
         return true;
    }, 'abc.');

    $.validator.addMethod('positiveint', function(value) {
        return (value > 0) && (value != 0) && (value == parseInt(value, 10));
    }, 'Enter a positive integer value.');

    $("#cartform").validate({
        rules: {
            "amount": {
                required: true,
                positiveint: true,
                notmorethan: true
            }
        },
        errorPlacement: function(error, element) {
            error.appendTo(element.next());
        }
    });

    $("button").click(function() {
        alert($("#cartform").valid());
    });

});