Skip to content

Commit

Permalink
feat: Support UTF-8 Email (#56)
Browse files Browse the repository at this point in the history
* Support UTF-8 Email

* Support UTF-8 Email

* Test case for UTF-8 Email
  • Loading branch information
kiznick authored Sep 9, 2021
1 parent 6b9a2a8 commit 36fc8fa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* 4.右则部分可分为两部分,第一部分为邮件提供商域名地址,第二部分为域名后缀,现已知的最短为2位。最长的为6为。
* 5.邮件提供商域可以包含特殊字符-、_、.
*/
email: /^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/,
email: /^[a-z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+([._\\-]*[a-z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*@([a-z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+[-a-z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+.){1,63}[a-z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/,
/**
* [ip ipv4、ipv6]
* "192.168.0.0"
Expand Down
2 changes: 1 addition & 1 deletion src/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var regexs = {
* 4.右则部分可分为两部分,第一部分为邮件提供商域名地址,第二部分为域名后缀,现已知的最短为2位。最长的为6为。
* 5.邮件提供商域可以包含特殊字符-、_、.
*/
email:/^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/,
email:/^[a-z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+([._\\-]*[a-z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*@([a-z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+[-a-z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+.){1,63}[a-z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/,
/**
* [ip ipv4、ipv6]
* "192.168.0.0"
Expand Down
9 changes: 7 additions & 2 deletions test/validator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ describe("validators", function () {
expect(v.isEmail('wowo@asdf.中国')).to.be.false;
expect(v.isEmail('wowo@中国.com')).to.be.false;
expect(v.isEmail('中@qq.com')).to.be.false;

expect(v.isEmail('wowo@中国.com')).to.be.false;
expect(v.isEmail('中@qq.com')).to.be.false;
expect(v.isEmail('email-test@universal-acceptance-test.icu')).to.be.true;
expect(v.isEmail('email-test@universal-acceptance-test.international ')).to.be.true;
expect(v.isEmail('อีเมลทดสอบ@ยูเอทดสอบ.ไทย')).to.be.true;
expect(v.isEmail('อีเมลทดสอบ@สวัสดีครับ.องค์กร.ไทย')).to.be.true;
});

it("isIp() IP验证", function () {
Expand Down Expand Up @@ -121,4 +126,4 @@ describe("validators", function () {
expect(v.isPercent(-101)).to.be.false;
});

});
});

0 comments on commit 36fc8fa

Please sign in to comment.