From 7bae0307136da6ce172e0ee298cba0a473fae06b Mon Sep 17 00:00:00 2001 From: Syed Sajjad Hussain Shah <52817156+syedsajjadkazmii@users.noreply.github.com> Date: Wed, 11 Oct 2023 09:44:03 +0500 Subject: [PATCH] fix: name field validations (#1069) --- .../RegistrationFields/NameField/validator.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/register/RegistrationFields/NameField/validator.js b/src/register/RegistrationFields/NameField/validator.js index 6831be300e..e62c227d08 100644 --- a/src/register/RegistrationFields/NameField/validator.js +++ b/src/register/RegistrationFields/NameField/validator.js @@ -1,13 +1,19 @@ import messages from '../../messages'; -export const INVALID_NAME_REGEX = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)?/gi; // eslint-disable-line no-useless-escape -export const urlRegex = new RegExp(INVALID_NAME_REGEX); +// regex more focused towards url matching +export const URL_REGEX = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)?/gi; // eslint-disable-line no-useless-escape + +// regex for html tags +export const HTML_REGEX = /<|>/u; + +// regex from backend +export const INVALID_NAME_REGEX = /https?:\/\/(?:[-\w.]|(?:%[\da-fA-F]{2}))*/g; const validateName = (value, formatMessage) => { let fieldError; if (!value.trim()) { fieldError = formatMessage(messages['empty.name.field.error']); - } else if (value && value.match(urlRegex)) { + } else if (URL_REGEX.test(value) || HTML_REGEX.test(value) || INVALID_NAME_REGEX.test(value)) { fieldError = formatMessage(messages['name.validation.message']); } return fieldError;