validation con jquery

by luissanchezm86

HTML

<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/additional-methods.js"></script>
<form id="myform">
    <input type="text" name="field1" />
    <br/>
    <input type="text" name="field2" />
</form>
<button id="event1">Test one element</button>
<br/>
<button id="event2">Test the whole form</button>
<a href="http://docs.jquery.com/Plugins/Validation" target="_blank">Validation Documentation</a>

CSS

a {
    display: block;
    position: absolute;
    bottom: 0;
}

JavaScript

$(document).ready(function () {

    $('#myform').validate({
        rules: {
            field1: {
                required: true
            },
            field2: {
                required: true
            }
        },
        submitHandler: function (form) { // for demo
            alert('valid form');
            return false;
        }
    });

    // programmatically check any element using the `.valid()` method.
    $('#event1').on('click', function () {
        $('input[name="field1"]').valid();
    });

    // programmatically check the entire form using the `.valid()` method.

    $('#event2').on('click', function () {
        $('#myform').valid();
    });

});