added email validation. The border of the input field becomes red if the input seems to be invalid.
This commit is contained in:
parent
2946fea85a
commit
d163875577
1 changed files with 12 additions and 0 deletions
|
|
@ -7,6 +7,9 @@ var Validation = {
|
||||||
username: {
|
username: {
|
||||||
characters: /^(|[A-Za-z0-9_]{0,32})$/,
|
characters: /^(|[A-Za-z0-9_]{0,32})$/,
|
||||||
length: [6, 32]
|
length: [6, 32]
|
||||||
|
},
|
||||||
|
email: {
|
||||||
|
characters: /^(([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,}))(, *(([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})))*$/
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
events: {
|
events: {
|
||||||
|
|
@ -15,10 +18,19 @@ var Validation = {
|
||||||
if(!Validation.rules.username.characters.test(this.value + String.fromCharCode(evt.keyCode))) {
|
if(!Validation.rules.username.characters.test(this.value + String.fromCharCode(evt.keyCode))) {
|
||||||
evt.preventDefault();
|
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() {
|
$(function() {
|
||||||
$("#user_username").keypress(Validation.events.usernameKeypress);
|
$("#user_username").keypress(Validation.events.usernameKeypress);
|
||||||
|
$("#user_email").keypress(Validation.events.emailKeypress);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue