@@ -9,27 +9,33 @@ export const DISALLOWED_WORDS = [
99
1010export const buildNameValidation = ( ) => {
1111 return Yup . string ( )
12+ . trim ( )
1213 . min ( 2 , "Name must be at least 2 characters" )
13- . matches ( / ^ [ A - Z a - z ] + $ / , "Name must only contain letters" )
14+ . matches ( / ^ (? ! . * ) [ a - z A - Z ] + $ / , "Name must only contain letters and non-consecutive internal spaces " )
1415 . required ( "Name is required" )
1516}
1617
1718export const buildUsernameValidation = ( ) => {
1819 return Yup . string ( )
20+ . trim ( )
1921 . min ( 2 , "Username must be at least 2 characters" )
20- . matches ( / ^ [ a - z A - Z 0 - 9 ] .* $ / , "Username must begin with a letter" )
21- . matches ( / ^ .* [ a - z A - Z 0 - 9 ] $ / , "Username must end with a letter" )
22+ . matches ( / ^ [ a - z A - Z 0 - 9 ] .* $ / , "Username must begin with a letter or number " )
23+ . matches ( / ^ .* [ a - z A - Z 0 - 9 ] $ / , "Username must end with a letter or number " )
2224 . matches ( / ^ (? ! .* ?_ _ ) [ a - z A - Z 0 - 9 _ ] + $ / , "Username must contain only alphanumeric characters and non-consecutive underscores" )
2325}
2426
2527export 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
3134export 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