File tree 1 file changed +11
-1
lines changed
42 - Simple Form Validation
1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -28,13 +28,23 @@ const isPasswordSecure = function(password) {
28
28
const format = new RegExp ( / ^ (? = .* [ a - z ] ) (? = .* [ A - Z ] ) (? = .* [ 0 - 9 ] ) (? = .* [ ! @ # $ % ^ & * ] ) (? = .{ 8 , } ) / )
29
29
return format . test ( String ( password ) )
30
30
}
31
+
32
+ //Only One space between two words will be passed
33
+ const isValidUserName = function ( username ) {
34
+ const format = new RegExp ( / ^ ( [ ^ \s ] * [ A - Z a - z 0 - 9 ] \s { 0 , 1 } ) [ ^ \s ] * $ / )
35
+ return format . test ( String ( username ) . toLowerCase ( ) )
36
+ }
37
+
31
38
const validateUsername = function ( ) {
32
39
let isInputValid = false
33
40
const username = username_input . value . trim ( )
34
41
35
42
if ( isBlank ( username ) ) {
36
43
setError ( username_input , "Username can't be blank." )
37
- } else if ( ! isBetween ( username . length ) ) {
44
+ } else if ( ! isValidUserName ( username ) ) {
45
+ setError ( username_input , `Username Invalid` ) ;
46
+ }
47
+ else if ( ! isBetween ( username . length ) ) {
38
48
setError ( username_input , `Username must be between ${ min } and ${ max } characters.` ) ;
39
49
} else {
40
50
setSuccess ( username_input ) ;
You can’t perform that action at this time.
0 commit comments