Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rionmonster/b9a5ca59b007976b87d3049eb32e45d3 to your computer and use it in GitHub Desktop.
Save rionmonster/b9a5ca59b007976b87d3049eb32e45d3 to your computer and use it in GitHub Desktop.
function Validation() {
var username = $("#username").val();
var password = $("#password").val();
var password2 = $("#password2").val();
var user_textLength = username.trim().length;
var pw_textLength = password.trim().length;
var x = email;
var atpos = x.indexOf("@");
var dotpos = x.lastIndexOf(".");
if (user_textLength <= 7) {
alert('Username must contain atleast 8 characters.');
document.getElementById("username").focus();
return false;
} else if (pw_textLength <= 7) {
alert('Password must contain atleast 8 characters.');
document.getElementById("password").focus();
return false;
} else if (password2 == "") {
alert('Please re-type your password');
document.getElementById("password2").focus();
return false;
} else if (password != password2) {
alert('Password and Re-typed Password do not match');
document.getElementById("password2").focus();
return false;
} else if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= x.length) {
alert("Not a valid e-mail address");
document.getElementById("email").focus();
return false;
} else {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment