diff --git a/app/client/src/utils/formhelpers.test.ts b/app/client/src/utils/formhelpers.test.ts new file mode 100644 index 0000000000..c621093332 --- /dev/null +++ b/app/client/src/utils/formhelpers.test.ts @@ -0,0 +1,43 @@ +import { isEmail } from "./formhelpers"; + +describe("isEmail test", () => { + it("Check whether the valid emails are recognized as valid", () => { + const validEmails = [ + "appsmith@yahoo.com", + "appsmith-100@yahoo.com", + "appsmith.100@yahoo.com", + "appsmith111@appsmith.com", + "appsmith-100@appsmith.net", + "appsmith.100@appsmith.com.au", + "appsmith@1.com", + "appsmith@gmail.com.com", + "appsmith+100@gmail.com", + "appsmith-100@yahoo-test.com", + ]; + + validEmails.forEach(validEmail => { + expect(isEmail(validEmail)).toBeTruthy(); + }); + }); + + it("Check whether the invalid emails are recognized as invalid", () => { + const invalidEmails = [ + "appsmith", + "appsmith@.com.my", + "appsmith123@gmail.a", + "appsmith123@.com", + "appsmith123@.com.com", + ".appsmith@appsmith.com", + "appsmith()*@gmail.com", + "appsmith@%*.com", + "appsmith..2002@gmail.com", + "appsmith.@gmail.com", + "appsmith@appsmith@gmail.com", + "appsmith@gmail.com.1a", + ]; + + invalidEmails.forEach(invalidEmail => { + expect(isEmail(invalidEmail)).toBeFalsy(); + }); + }); +}); diff --git a/app/client/src/utils/formhelpers.ts b/app/client/src/utils/formhelpers.ts index 7fbd159be4..f6dcf550e6 100644 --- a/app/client/src/utils/formhelpers.ts +++ b/app/client/src/utils/formhelpers.ts @@ -14,6 +14,6 @@ export const isStrongPassword = (value: string) => { // TODO (abhinav): Use a regex which adheres to standards RFC5322 export const isEmail = (value: string) => { - const re = /^([A-Za-z0-9_\-.])+@([A-Za-z0-9_\-.])+.([A-Za-z]{2,5})$/; + const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(value); };