Skip to content

Commit

Permalink
fixing bug in email validation regex and updating tests fixes mozilla…
Browse files Browse the repository at this point in the history
  • Loading branch information
cacois committed Aug 20, 2013
1 parent ae9a924 commit ca86480
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ check = require('validator').check;

var hostnameRegex = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/;
// HTML5 email regex from: http://blog.gerv.net/2011/05/html5_email_address_regexp/
var emailRegex = /^[a-zA-Z0-9.!#$%&'*+\/=?\^_`{|}~\-]+@[a-zA-Z0-9](?:[a-zA-Z0-9]{0,253}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9]{0,253}[a-zA-Z0-9])?)*$/;
var emailRegex = /^[a-zA-Z0-9.!#$%&'*+\/=?\^_`{|}~\-]+@[a-zA-Z0-9](?:[a-zA-Z0-9\-]{0,253}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9]{0,253}[a-zA-Z0-9])?)*$/;

var types = {
email: function(x) {
Expand Down
9 changes: 9 additions & 0 deletions tests/email-validation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var validEmail4 = '[email protected]';
var invalidEmail1 = '[email protected]';
var invalidEmail2 = 'test@';
var invalidEmail3 = '[email protected]';
var invalidEmail4 = '[email protected]';

suite.addBatch({
"Testing first valid email address": {
Expand Down Expand Up @@ -85,6 +86,14 @@ suite.addBatch({
"returns 400": function(err, r) {
assert.strictEqual(r.code, 400);
}
},
"Testing fourth invalid email address": {
topic: wsapi.get('/wsapi/address_info', {
email: invalidEmail4
}),
"returns 400": function(err, r) {
assert.strictEqual(r.code, 400);
}
}
});

Expand Down

0 comments on commit ca86480

Please sign in to comment.