Skip to content

Commit dbb0b5c

Browse files
committed
feat: add email regex pattern to constants and refactor email validation function
1 parent df25b04 commit dbb0b5c

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

src/Common/Constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export const PATTERNS = {
5151
CONFIG_MAP_AND_SECRET_KEY: /^[-._a-zA-Z0-9]+$/,
5252
CONFIGMAP_AND_SECRET_NAME: /^[a-z0-9][a-z0-9-.]*[a-z0-9]$/,
5353
ALPHANUMERIC_WITH_SPECIAL_CHAR_AND_SLASH: /^[A-Za-z0-9._/-]+$/, // allow alphanumeric,(.) ,(-),(_),(/)
54+
// eslint-disable-next-line no-useless-escape
55+
EMAIL: /^(([^<>()\[\]\\.,;:\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,}))$/,
5456
}
5557

5658
const GLOBAL_CONFIG_TEMPLATES_DEVTRON_APP = '/global-config/templates/devtron-apps'

src/Shared/validations.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,7 @@ export const validateEmail = (email: string): ValidationResponseType => {
506506
}
507507
}
508508

509-
const re =
510-
// eslint-disable-next-line no-useless-escape
511-
/^(([^<>()\[\]\\.,;:\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,}))$/
512-
const result = re.test(String(email).toLowerCase())
509+
const result = PATTERNS.EMAIL.test(String(email).toLowerCase())
513510

514511
if (result) {
515512
return {

0 commit comments

Comments
 (0)