Merge branch 'email-validation' of https://github.com/themasch/diaspora into themasch-email-validation
This commit is contained in:
commit
045ba7c419
2 changed files with 30 additions and 0 deletions
|
|
@ -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.keyCode === 0) { return; }
|
||||
if(!Validation.rules.email.characters.test(this.value + String.fromCharCode(evt.keyCode))) {
|
||||
$('#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);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -7,6 +7,13 @@ describe("Validation", function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
describe("email", function() {
|
||||
describe("characters", function() {
|
||||
it("is the regex for checking if the input is a valid list of e-mail addresses", function() {
|
||||
expect((typeof Validation.rules.email.characters.test === "function")).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("events", function() {
|
||||
describe("usernameKeypress", function() {
|
||||
|
|
@ -16,5 +23,16 @@ describe("Validation", function() {
|
|||
expect(Validation.rules.username.characters.test("ffffffffffffffffffffffffffffffffff")).toBeFalsy();
|
||||
});
|
||||
});
|
||||
describe("emailKeypress", function() {
|
||||
it("colors the border red if the input seems to be a invalid list", function() {
|
||||
expect(Validation.rules.email.characters.test("user@example.com")).toBeTruthy();
|
||||
expect(Validation.rules.email.characters.test("user@example.com, user@example.com")).toBeTruthy();
|
||||
expect(Validation.rules.email.characters.test("user@example.com, user@example.com, user@example.com")).toBeTruthy();
|
||||
expect(Validation.rules.email.characters.test("user@example.com user@example.com")).toBeFalsy();
|
||||
expect(Validation.rules.email.characters.test("user@examplecom")).toBeFalsy();
|
||||
expect(Validation.rules.email.characters.test("userexample.com")).toBeFalsy();
|
||||
expect(Validation.rules.email.characters.test("userexamplecom")).toBeFalsy();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue