added email validation. The border of the input field becomes red if the input seems to be invalid.

This commit is contained in:
Mark Schmale 2010-12-12 13:23:00 -08:00
parent 2946fea85a
commit d163875577

View file

@ -7,6 +7,9 @@ var Validation = {
username: {
characters: /^(|[A-Za-z0-9_]{0,32})$/,
length: [6, 32]
},
email: {
characters: /^(([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,}))(, *(([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})))*$/
}
},
events: {
@ -15,10 +18,19 @@ var Validation = {
if(!Validation.rules.username.characters.test(this.value + String.fromCharCode(evt.keyCode))) {
evt.preventDefault();
}
},
emailKeypress: function(evt) {
if(evt.charCode === 0) { return; }
if(!Validation.rules.email.characters.test(this.value + String.fromCharCode(evt.charCode))) {
$('#user_email').css('border-color', '#8B0000');
} else {
$('#user_email').css('border-color', '#666666');
}
}
}
};
$(function() {
$("#user_username").keypress(Validation.events.usernameKeypress);
$("#user_email").keypress(Validation.events.emailKeypress);
});