Skip to content

Commit

Permalink
Merge pull request #451 from Heaven-Tonight/reg-update-forms-validati…
Browse files Browse the repository at this point in the history
…on-enhancements

[#443] fixed username field feedback error displaying ("no leading/trailing/middle whitespaces" rule)
  • Loading branch information
dzencot authored Apr 10, 2024
2 parents 352c5f2 + c86d586 commit 33559f0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion frontend/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 - _ .",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"emailIsUsed": "Этот адрес уже зарегистрирован",
"incorrectEmail": "Некорректная электронная почта",
"incorrectPassword": "Допустимы только латинские буквы, цифры и знаки препинания",
"incorrectUsername": "В логине не должно быть пробелов",
"incorrectUsername": "Допустимы только латинские буквы, цифры, и символы - _",
"passwordLength": "От 8 до 30 символов",
"requiredField": "Обязательное поле",
"singleWord": "Допустимы буквы латинского алфавита, цифры и символы -_ .",
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/utils/validationSchemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down

0 comments on commit 33559f0

Please sign in to comment.