File tree 3 files changed +41
-2
lines changed
42 - Simple Form Validation
3 files changed +41
-2
lines changed Original file line number Diff line number Diff line change @@ -4,17 +4,26 @@ var remove_fields = document.getElementById('remove_fields');
4
4
5
5
add_more_fields . onclick = function ( ) {
6
6
var newField = document . createElement ( 'input' ) ;
7
+ var input_tags = survey_options . getElementsByTagName ( 'input' ) ;
7
8
newField . setAttribute ( 'type' , 'text' ) ;
8
9
newField . setAttribute ( 'name' , 'survey_options[]' ) ;
9
10
newField . setAttribute ( 'class' , 'survey_options' ) ;
10
11
newField . setAttribute ( 'siz' , 50 ) ;
11
12
newField . setAttribute ( 'placeholder' , 'Another Field' ) ;
12
13
survey_options . appendChild ( newField ) ;
14
+ if ( input_tags . length > 2 ) {
15
+ document . getElementById ( "remove_fields" ) . style . visibility = "visible" ;
16
+
17
+ }
13
18
}
14
19
15
20
remove_fields . onclick = function ( ) {
16
21
var input_tags = survey_options . getElementsByTagName ( 'input' ) ;
17
22
if ( input_tags . length > 2 ) {
18
23
survey_options . removeChild ( input_tags [ ( input_tags . length ) - 1 ] ) ;
19
24
}
25
+ else {
26
+ document . getElementById ( "remove_fields" ) . style . visibility = "hidden" ;
27
+
28
+ }
20
29
}
Original file line number Diff line number Diff line change @@ -52,12 +52,32 @@ input[type="text"]:focus {
52
52
}
53
53
54
54
# add_fields {
55
+ background-color : # 4CAF50 ; /* Green */
56
+ border : none;
57
+ border-radius : 10px ;
55
58
color : white;
59
+ padding : 15px 32px ;
60
+ text-align : center;
61
+ text-decoration : none;
62
+ display : inline-block;
63
+ font-size : 16px ;
64
+
56
65
}
57
66
67
+
68
+
58
69
# remove_fields {
70
+ background-color : # ee052c ; /* Red */
71
+ border : none;
72
+ border-radius : 10px ;
73
+ margin-left : 70px ;
59
74
color : white;
60
- float : right;
75
+ padding : 15px 32px ;
76
+ text-align : center;
77
+ text-decoration : none;
78
+ display : inline-block;
79
+ font-size : 16px ;
80
+
61
81
}
62
82
63
83
.controls a {
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