From d6db74b1e840c5d3b51f4e35a6a6500426f6d600 Mon Sep 17 00:00:00 2001 From: Nopachat Kalayanapan Date: Wed, 15 Sep 2021 22:54:30 +0700 Subject: [PATCH] add Thai email support with test cases --- index.js | 2 +- test.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 73d15c9..c76d2b5 100644 --- a/index.js +++ b/index.js @@ -7,4 +7,4 @@ * stack@lebron.technology */ -module.exports = /^([\w_\.\-\+])+\@([\w\-]+\.)+([\w]{2,10})+$/; +module.exports = /^[a-z0-9ก-๛\-\._\+]+@[ก-๛a-z][ก-๛a-z0-9\+\-\.]*[ก-๛a-z]{2,}$/; diff --git a/test.js b/test.js index 3e8dd82..f0b3c15 100644 --- a/test.js +++ b/test.js @@ -16,6 +16,13 @@ describe('email regex', function() { assert.equal(regex.test('t.obi+_ferret@vision.com'), true); }); + it('should match thai input', function() { + assert.equal(regex.test('email-test@universal-acceptance-test.international'), true); + assert.equal(regex.test('email-test@universal-acceptance-test.icu'), true); + assert.equal(regex.test('อีเมลทดสอบ@ยูเอทดสอบ.ไทย'), true); + assert.equal(regex.test('อีเมลทดสอบ@ทีเอชนิค.องค์กร.ไทย'), true); + }); + it('should catch incorrect input', function() { assert.equal(regex.test('*(*(*()))'), false); assert.equal(regex.test('foobar@@hello.com'), false);