Speed up development with full-stack environments for every branch.

Learn More

How to use jQuery-validation - Simple login form

17921 Runs 72674 Views 28002 Copies
Saved

Saved

gtsolutions 373

gtsolutions
published 4 years ago

<html> 
    <head>
        <meta charset="utf-8">
        <title>jQuery Validation Plugin Examples</title>

        <!-- Bootstrap CSS used for styling the demo pages-->
        <link rel="stylesheet" href="css/bootstrap.min.css">
        <link rel="stylesheet" href="css/style.css">
    </head>

    <body>
        <!-- basic validation of a login form -->
        <form class="form" id="example1">
            <div class="form-group">
                <label>Basic login form example</label>
            </div>
            <div class="form-group">
                <label for="example1-email">Email address</label>
                <input type="email" class="form-control" id="example1-email" name="example1-email" placeholder="Enter email">
            </div>
            <div class="form-group">
                <label for="example1-password">Password</label>
                <input type="password" class="form-control" id="example1-password" name="example1-password" placeholder="Password">
            </div>
            <button type="submit" class="btn btn-primary">Submit</button>
        </form>

        <!-- Load jQuery and jQuery-Validate scripts -->
        <script src="js/jquery.js"></script>
        <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
        <script>
            // When the document is ready
            $(document).ready(function () {
                
                
                //validation rules
                //by default it will append a <label class="error> element to the invalid input
                //and will add a "error" class to the input
                $("#example1").validate({
                    rules: {
                        "example1-email": {
                            required: true,
                            email: true
                        },  
                        "example1-password": {
                            required: true,
                            minlength: 5
                        } 
                    }
                });
            });
        </script>
    </body>
</html>
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).