Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit af6f943

Browse files
KevinBrogancaitp
authored andcommitted
fix(input): modify email validation regexp to match rfc1035
Previously, domain parts which began with or ended with a dash, would be accepted as valid. This CL matches Angular's email validation with that of Chromium and Firefox. Closes #6026
1 parent 0a51a05 commit af6f943

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/ng/directive/input.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
var URL_REGEXP = /^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/;
14-
var EMAIL_REGEXP = /^[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9-]+(\.[a-z0-9-]+)*$/i;
14+
var EMAIL_REGEXP = /^[a-z0-9!#$%&'*+/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i;
1515
var NUMBER_REGEXP = /^\s*(\-|\+)?(\d+|(\d*(\.\d*)))\s*$/;
1616
var DATE_REGEXP = /^(\d{4})-(\d{2})-(\d{2})$/;
1717
var DATETIMELOCAL_REGEXP = /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d)$/;

test/ng/directive/inputSpec.js

+4
Original file line numberDiff line numberDiff line change
@@ -2366,6 +2366,10 @@ describe('input', function() {
23662366
expect(EMAIL_REGEXP.test('a@b.museum')).toBe(true);
23672367
expect(EMAIL_REGEXP.test('a@B.c')).toBe(true);
23682368
expect(EMAIL_REGEXP.test('a@.b.c')).toBe(false);
2369+
expect(EMAIL_REGEXP.test('a@-b.c')).toBe(false);
2370+
expect(EMAIL_REGEXP.test('a@b-.c')).toBe(false);
2371+
expect(EMAIL_REGEXP.test('a@3b.c')).toBe(true);
2372+
expect(EMAIL_REGEXP.test('a@b')).toBe(true);
23692373
});
23702374
});
23712375
});

0 commit comments

Comments
 (0)