Skip to content

Commit 06c99dd

Browse files
committed
496: Trim whitespace in validations and disallow consecutive spaces in name
1 parent 5d6cd09 commit 06c99dd

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/client/src/pages/UserManagement/Validations.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,33 @@ export const DISALLOWED_WORDS = [
99

1010
export const buildNameValidation = () => {
1111
return Yup.string()
12+
.trim()
1213
.min(2, "Name must be at least 2 characters")
13-
.matches(/^[A-Za-z]+$/, "Name must only contain letters")
14+
.matches(/^(?!.* )[a-zA-Z ]+$/, "Name must only contain letters and non-consecutive internal spaces")
1415
.required("Name is required")
1516
}
1617

1718
export const buildUsernameValidation = () => {
1819
return Yup.string()
20+
.trim()
1921
.min(2, "Username must be at least 2 characters")
20-
.matches(/^[a-zA-Z0-9].*$/, "Username must begin with a letter")
21-
.matches(/^.*[a-zA-Z0-9]$/, "Username must end with a letter")
22+
.matches(/^[a-zA-Z0-9].*$/, "Username must begin with a letter or number")
23+
.matches(/^.*[a-zA-Z0-9]$/, "Username must end with a letter or number")
2224
.matches(/^(?!.*?__)[a-zA-Z0-9_]+$/, "Username must contain only alphanumeric characters and non-consecutive underscores")
2325
}
2426

2527
export const buildRoleValidation = () => {
2628
return Yup.string()
29+
.trim()
2730
.oneOf(["user", "editor", "admin"], "Role must be one of the following: user/editor/admin")
2831
.required("Role is required")
2932
}
3033

3134
export const buildPasswordValidation = (username) => {
3235
return Yup.string()
36+
.trim()
37+
38+
3339
.test(
3440
"no-disallowed-words",
3541
"Password cannot include 'dog', 'cat', 'password', or your username",

0 commit comments

Comments
 (0)