Skip to content

Commit

Permalink
forms: fix for email addresses ending in _ [#177 state:review]
Browse files Browse the repository at this point in the history
  • Loading branch information
jakearchibald committed Sep 21, 2009
1 parent ae23587 commit 196ceb5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/forms/forms.js
Expand Up @@ -706,7 +706,7 @@ glow.forms.tests = {
var message = opts.message || opts._localeModule.TEST_MESSAGE_IS_EMAIL;

for (var i = 0, len = values.length; i < len; i++) {
if (!/^\s*[A-Za-z0-9](([_\.\-]*[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})\s*$/.test(values[i])) {
if (!/^\s*[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}\s*$/i.test(values[i])) {
callback(glow.forms.FAIL, message);
return;
}
Expand Down
12 changes: 6 additions & 6 deletions test/glow/forms/forms.js
Expand Up @@ -578,7 +578,7 @@ t.test("glow.forms.tests.isEmail", function() {
var myForm = new glow.forms.Form(myFormElem);
glow.events.addListener(myForm, "validate", function(results){validateResults = results; return false; });

t.equals(typeof glow.forms.tests.isEmail, "function", "glow.forms.tests.isEmail is a function.");
t.equals(typeof glow.forms.tests.isEmail, "function", "glow.forms.tests.isEmail is a function.");

myForm
.addTests(
Expand All @@ -602,15 +602,15 @@ t.test("glow.forms.tests.isEmail", function() {
username: "1abc-123@abc.a1-b2.xyz.co.uk",
age: "abc@abc@.com",
email: "abc123",
email_confirm: " abc123@abc.com "
email_confirm: " abc123_@abc.com "
});

myForm.validate('submit');

t.equals(validateResults.fields[0].result, glow.forms.PASS, "isEmail passes when value is valid email.");
t.equals(validateResults.fields[1].result, glow.forms.FAIL, "isEmail fails when value is almost a valid email.");
t.equals(validateResults.fields[2].result, glow.forms.FAIL, "isEmail fails when value is not a valid email.");
t.equals(validateResults.fields[3].result, glow.forms.PASS, "isEmail passes when value is a valid email, but has whitespace padding.");
t.equals(validateResults.fields[0].result, glow.forms.PASS, "isEmail passes when value is valid email.");
t.equals(validateResults.fields[1].result, glow.forms.FAIL, "isEmail fails when value is almost a valid email.");
t.equals(validateResults.fields[2].result, glow.forms.FAIL, "isEmail fails when value is not a valid email.");
t.equals(validateResults.fields[3].result, glow.forms.PASS, "isEmail passes when value is a valid email, but has whitespace padding and underscore");

//clean up
resetFormsTestElement();
Expand Down

0 comments on commit 196ceb5

Please sign in to comment.