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); });