jQuery Validation

Using jQuery validation package to handle email validation with checking against an existing database in just one function.

http://docs.jquery.com/Plugins/Validation#Plugin_methods
http://docs.jquery.com/Plugins/Validation/Methods/remote
http://docs.jquery.com/Plugins/Validation#The_Marketo_sign-up_form
http://docs.jquery.com/Plugins/Validation#The_Remember_The_Milk_sign-up_...
http://uscpclub.com/webapp/views/loginAndRegistrationView.php (loginAndRegister.js)

$(document).ready(function(){
  $("#registerErrors").hide();
 
  //automatically hides the registration div and shows the login div
  $("#loginContainer").show();
  $("#registrationContainer").hide();
 
  //shows the login div if not already shown
  $("#loginButton").click(function () {
    $("#registerErrors").hide();
    if($("#loginContainer").is(":hidden")) {
      $("#incorrectLogin").hide();
      $("#logoutSuccess").hide();
      $("#memberRegistrationUsername").val('');
      $("#memberRegistrationPassword").val('');
      $("#memberConfirmPassword").val('');
      $("#memberRegistrationEmail").val('');
      $("#loginContainer").show("blind", "slow");
      $("#registrationContainer").hide("blind", "fast");
      $("#memberLoginUsername").focus();
    }
  });
 
  //shows the registration div if not already shown
  $("#registerButton").click(function () {
    $("#registerErrors").hide();
    if($("#registrationContainer").is(":hidden")) {
      $("#incorrectLogin").hide();
      $("#logoutSuccess").hide();
      $("#memberLoginUsername").val('');
      $("#memberLoginPassword").val('');
      $("#registrationContainer").show("blind", "slow");
      $("#loginContainer").hide("blind", "fast");
      $("#memberRegistrationUsername").focus();
    }
  });
 
  //validates the form
  $("#registrationForm").validate({
    //sets the rules for validation
    rules: {
      username: {
        required: true,
        minlength: 5,
        remote: {
          url: "/webapp/controllers/checkIfUserExists.php",
          type: "get"
        }
      },
      password: "required",
      confirmpassword: {
        required: true,
        equalTo: "#memberRegistrationPassword"
      },
      email: {
        required: true,
        email: true
      }
    },
    //sets the error messages
    messages: {
      username: {
        required: "Enter username",
        minlength: jQuery.format("Enter at least {0} characters"),
        remote: jQuery.format("'{0}' is already in use")
      },
      password: {
        required: "Enter password"
      },
      confirmpassword: {
        equalTo: "Passwords don't match"
      },
      email: {
        required: "Enter email",
        email: "Not a valid email address"
      }
    },
    errorLabelContainer: "#registerErrors",
    wrapper: "li"
  });
});

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question? Are you human?
10 + 1 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.