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

Commit 816b842

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 873acf8 commit 816b842

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
@@ -9,7 +9,7 @@
99
*/
1010

1111
var URL_REGEXP = /^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/;
12-
var EMAIL_REGEXP = /^[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9-]+(\.[a-z0-9-]+)*$/i;
12+
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;
1313
var NUMBER_REGEXP = /^\s*(\-|\+)?(\d+|(\d*(\.\d*)))\s*$/;
1414

1515
var inputType = {

test/ng/directive/inputSpec.js

+4
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,10 @@ describe('input', function() {
10191019
expect(EMAIL_REGEXP.test('a@b.museum')).toBe(true);
10201020
expect(EMAIL_REGEXP.test('a@B.c')).toBe(true);
10211021
expect(EMAIL_REGEXP.test('a@.b.c')).toBe(false);
1022+
expect(EMAIL_REGEXP.test('a@-b.c')).toBe(false);
1023+
expect(EMAIL_REGEXP.test('a@b-.c')).toBe(false);
1024+
expect(EMAIL_REGEXP.test('a@3b.c')).toBe(true);
1025+
expect(EMAIL_REGEXP.test('a@b')).toBe(true);
10221026
});
10231027
});
10241028
});

0 commit comments

Comments
 (0)