Skip to content
  • home
  • portfolio
  • web design journal
  • blog
    • adventure
    • san diego
    • urbanity & architecture
    • projects
    • website design
Blog Web Dev Easy jQuery Validator Setup

Easy jQuery Validator Setup

By Forrest Smith - Drempd.com

It seems like it always takes me a bit to figure out how to get the super-great jquery validator to work, and I have to go work my way through the documentation on the site — which has a lot of information, but makes it a little harder for me to just set it up and get it running. There is an easy method of implementation, but adding classes to elements, such as ‘required’, or ’email’. Unfortunately, on some versions of chrome, and earlier versions of Internet Explorer, this method didn’t seem to work, so I needed to use the more complex implementation and build out some jquery. The following should get it up and running easily and quickly.

This assumes a form with an id of ‘form-name’, and an text input, named ‘fld-email’ (this references the ‘name’ attribute, not the ‘id’ attribute) that is required, and needs to be checked that it is a valid email address. When the form is submitted, it will validate it, and if it passes, continue the submission process. If it doesn’t pass, it will keep the form visible without a page refresh, and highlight the fields that didn’t pass validation.

<script type="text/javascript" src="jquery-validator.js"></script>
<script type="text/javascript">
$(document).ready(function () {
    $('#form-name').validate({
        rules: {
            fld-email: {
                required: true,
                email: true
            }
        }
    });
    $('#form-name').submit(function () {
        if ($(this).valid() == true) {
            form.submit();
        }
    });
});
</script>
Posted on January 16, 2014August 26, 2022 in Web Dev
  • Adventure

    • adventure
    • gravelgrinding
    • hiking
    • running
  • The Built Environment

    • architecture
    • urbanity
  • Locations

    • san diego
    • portland
  • Freelance Life

    • freelancing
    • productivity
  • Web Dev

    • css
    • entrepreneurship
    • git
    • handlebars
    • html
    • inkscape
    • photoshop
    • php
    • sass
    • web design
    • web development
    • saphire

drempd | san diego, ca


home contact

adventures san diego urbanity and architecture projects stream website design

portfolio resume san diego web design freelance web designer

custom web design responsive web design website maintenance