ok im not sure why but it doesnt seem to like having some of your variables in the dom.ready, frankly i have no idea why. I ran this through jshint.com, there still seems to be an issue with unescaped - 's in the var filter, but maybe one of the more advanced guys could explain why.
This is what I have so far, perhaps it will get you in the right direction.
Code:
var username = $("#username");
var usernameInfo = $("#usernameInfo");
var emailadres = $("#emailadres");
var emailadresInfo = $("#emailadresInfo");
var password1 = $("#password1");
var password1Info = $("#password1Info");
var password2 = $("#password2");
var password2Info = $("#password2Info");
$(document).ready(function() {
function validateUserName() {
usernameInfo.html('<img src="loader.gif" align="absmiddle"> ');
if(username.val().length < 3) {
username.removeClass("okay");
username.addClass("error");
usernameInfo.html('<img src="/images/icons/exclamation.png">');
return false;
}
else {
username.removeClass("error");
username.addClass("okay");
usernameInfo.html('<img src="/images/icons/accept.png">');
return true;
}
}
function validateEmail() {
emailadresInfo.html('<img src="loader.gif" align="absmiddle"> ');
var a = $("#emailadres").val();
var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
if(filter.test(a)) {
emailadres.removeClass("error");
emailadres.addClass("okay");
emailadresInfo.html('<img src="/images/icons/accept.png">');
return true;
}
else {
emailadres.removeClass("okay");
emailadres.addClass("error");
emailadresInfo.html('<img src="/images/icons/exclamation.png">');
return false;
}
}
function validatePassword1(){
if(password1.val().length < 4){
password1.removeClass("okay");
password1.addClass("error");
password1Info.html('<img src="/images/icons/exclamation.png">');
return false;
}
else {
password1.removeClass("error");
password1.addClass("okay");
password1Info.html('<img src="/images/icons/accept.png">');
return true;
}
}
function validatePassword2(){
if( password1.val() != password2.val() ){
password2.removeClass("okay");
password2.addClass("error");
password2Info.html('<img src="/images/icons/exclamation.png">');
return false;
}
else{
password2.removeClass("error");
password2.addClass("okay");
password2Info.html('<img src="/images/icons/accept.png">');
return true;
}
}
username.blur(validateUserName);
username.keyup(validateUserName);
emailadres.blur(validateEmail);
emailadres.keyup(validateEmail);
password1.blur(validatePassword1);
password1.keyup(validatePassword1);
password2.blur(validatePassword2);
password2.keyup(validatePassword2);
});
Bookmarks