Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make validator a bit smarter about allowed email addresses. A number of

special characters are valid in the email address spec.
http://en.wikipedia.org/wiki/Email_address#Syntax

R=nnaze
DELTA=7 (2 added, 0 deleted, 5 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=6252


git-svn-id: http://closure-library.googlecode.com/svn/trunk@2505 0b95b8e8-c90f-11de-9d4f-f947ee5921c8
  • Loading branch information...
commit 82bb7b5af08ba386156771d8460d1d7d17e4bb72 1 parent aa007a9
mariakhomenko@google.com authored
View
9 closure/goog/format/emailaddress.js
@@ -198,10 +198,11 @@ goog.format.EmailAddress.isValidAddress = function(str) {
*/
goog.format.EmailAddress.isValidAddrSpec = function(str) {
// This is a fairly naive implementation, but it covers 99% of use cases.
- // For example, having two dots in a row isn't valid, but I don't think we
- // need that level of validation. Also, things like [a@b]@c.com is valid, but
- // I don't think anyone would accept it.
- var filter = /^[+a-zA-Z0-9_.-]+@([a-zA-Z0-9-]+\.)+[a-zA-Z0-9]{2,6}$/;
+ // For more details, see http://en.wikipedia.org/wiki/Email_address#Syntax
+ // TODO(mariakhomenko): we should also be handling i18n domain names as per
+ // http://en.wikipedia.org/wiki/Internationalized_domain_name
+ var filter =
+ /^[+a-zA-Z0-9_.!#$%&'*\/=?^`{|}~-]+@([a-zA-Z0-9-]+\.)+[a-zA-Z0-9]{2,6}$/;
return filter.test(str);
};
View
3  closure/goog/format/emailaddress_test.html
@@ -176,7 +176,8 @@
function testIsValid() {
var valid = [
'e@b.eu', '<a.b+foo@c.com>', 'eric <e@b.com>', '"e" <e@b.com>',
- 'a@FOO.MUSEUM', 'bla@b.co.ac.uk', 'bla@a.b.com'];
+ 'a@FOO.MUSEUM', 'bla@b.co.ac.uk', 'bla@a.b.com', 'o\'hara@gm.com',
+ 'user+someone@gmail.com', '!/#$%&\'*+-=~|`{}?^_@expample.com' ];
var invalid = [
'e', '', 'e @c.com', 'a@b', 'foo.com', 'foo@c..com'];
goog.array.forEach(valid, function(str) {
Please sign in to comment.
Something went wrong with that request. Please try again.