diff --git a/frontend/src/locales/en.json b/frontend/src/locales/en.json index e2f9d564..875866eb 100644 --- a/frontend/src/locales/en.json +++ b/frontend/src/locales/en.json @@ -48,7 +48,7 @@ "emailIsUsed": "This email address is already being used", "incorrectEmail": "Incorrect email", "incorrectPassword": "Only Latin letters, numbers and punctuation are allowed", - "incorrectUsername": "There must be no spaces in the username", + "incorrectUsername": "Only Latin letters, numbers and symbols - _ are allowed", "passwordLength": "From 8 to 30 characters", "requiredField": "Required field", "singleWord": "Allowed latin letters, numbers and symbols - _ .", diff --git a/frontend/src/locales/ru.json b/frontend/src/locales/ru.json index d4391ccc..cf3bce82 100644 --- a/frontend/src/locales/ru.json +++ b/frontend/src/locales/ru.json @@ -48,7 +48,7 @@ "emailIsUsed": "Этот адрес уже зарегистрирован", "incorrectEmail": "Некорректная электронная почта", "incorrectPassword": "Допустимы только латинские буквы, цифры и знаки препинания", - "incorrectUsername": "В логине не должно быть пробелов", + "incorrectUsername": "Допустимы только латинские буквы, цифры, и символы - _", "passwordLength": "От 8 до 30 символов", "requiredField": "Обязательное поле", "singleWord": "Допустимы буквы латинского алфавита, цифры и символы -_ .", diff --git a/frontend/src/utils/validationSchemas.js b/frontend/src/utils/validationSchemas.js index a13f929e..227841e5 100644 --- a/frontend/src/utils/validationSchemas.js +++ b/frontend/src/utils/validationSchemas.js @@ -4,6 +4,7 @@ import { string } from 'yup'; const USERNAME_MIN_LENGTH = 3; const USERNAME_MAX_LENGTH = 16; +const USERNAME_REGEX = /^[a-zA-Z0-9_-]+$/; const PASSWORD_MIN_LENGTH = 8; const PASSWORD_MAX_LENGTH = 30; @@ -13,12 +14,10 @@ export const SNIPPET_NAME_MAX_LENGTH = 30; export const username = () => string() - .trim() .required('errors.validation.requiredField') + .matches(USERNAME_REGEX, 'errors.validation.incorrectUsername') .min(USERNAME_MIN_LENGTH, 'errors.validation.usernameLength') - .max(USERNAME_MAX_LENGTH, 'errors.validation.usernameLength') - .matches(/^[\w\S]*$/, 'errors.validation.incorrectUsername'); - + .max(USERNAME_MAX_LENGTH, 'errors.validation.usernameLength'); export const email = () => string() .trim()