Skip to content

Commit

Permalink
fix: name field validations (#1069)
Browse files Browse the repository at this point in the history
  • Loading branch information
syedsajjadkazmii authored Oct 11, 2023
1 parent 7b4714a commit 7bae030
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/register/RegistrationFields/NameField/validator.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 7bae030

Please sign in to comment.