From 84c6e436d78b48dccdb35d7d97efb4e055b164b0 Mon Sep 17 00:00:00 2001 From: Matt Kingshott <51963402+mattkingshott@users.noreply.github.com> Date: Wed, 27 Jul 2022 09:35:41 +0100 Subject: [PATCH] fixed email validation bug --- package.json | 2 +- src/iodine.js | 2 +- tests/test.js | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index dbf50d1..676616b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kingshott/iodine", - "version": "8.1.0", + "version": "8.2.0", "description": "A micro client-side validation library", "repository": { "type": "git", diff --git a/src/iodine.js b/src/iodine.js index 5412949..726f4b9 100644 --- a/src/iodine.js +++ b/src/iodine.js @@ -275,7 +275,7 @@ export default class Iodine */ assertEmail(value) { - let regex = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"; + let regex = "^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$"; return new RegExp(regex).test(String(value).toLowerCase()); } diff --git a/tests/test.js b/tests/test.js index 7b38ec0..b2f5983 100644 --- a/tests/test.js +++ b/tests/test.js @@ -153,6 +153,8 @@ test('email values', () => expect(window.Iodine.assertEmail('m@i.co.uk')).toBe(true); expect(window.Iodine.assertEmail('😃@i.com')).toBe(false); expect(window.Iodine.assertEmail('')).toBe(false); + expect(window.Iodine.assertEmail('john@example.com ')).toBe(false); + expect(window.Iodine.assertEmail('john@example.com extra')).toBe(false); expect(window.Iodine.assertEmail('45454.com')).toBe(false); expect(window.Iodine.assertEmail('sdfsf@')).toBe(false); });