18
18
19
19
var errors = [ ] ;
20
20
21
+ // Regular expression check name field is not empty
22
+ var nameRegex = / .+ / ;
23
+ if ( ! nameRegex . test ( name ) ) {
24
+ const nameError = document . getElementById ( "name-error" ) ;
25
+ nameError . style . display = "block" ;
26
+ const nameField = document . getElementById ( "name" ) ;
27
+ nameField . style . outline = "2px solid red" ;
28
+ errors . push ( "Name is invalid" ) ;
29
+ } else {
30
+ const nameError = document . getElementById ( "name-error" )
31
+ nameError . style . display = "none" ;
32
+ const nameField = document . getElementById ( "name" )
33
+ nameField . style . outline = "" ;
34
+ }
35
+
21
36
// Regular expression check for industry name
22
37
var industryRegex = / ^ [ A - Z a - z - ] + $ / ;
23
38
if ( ! industryRegex . test ( industry ) ) {
48
63
employeesField . style . outline = "" ;
49
64
}
50
65
66
+ // Add regular expression check to make sure plan field is not empty
67
+ var planRegex = / .+ / ;
68
+ if ( ! planRegex . test ( plan ) ) {
69
+ planError = document . getElementById ( "plan-error" ) ;
70
+ planError . style . display = "block" ;
71
+ plan = document . getElementById ( "plan" ) ;
72
+ plan . style . outline = "2px solid red" ;
73
+ errors . push ( "Plan is invalid" ) ;
74
+ } else {
75
+ const planError = document . getElementById ( "plan-error" ) ;
76
+ planError . style . display = "none" ;
77
+ const plan = document . getElementById ( "plan" ) ;
78
+ plan . style . outline = "" ;
79
+ }
51
80
52
81
// Add regular expression check for total billed
53
82
var billedRegex = / ^ [ 0 - 9 ] + $ / ;
128
157
< h3 > Sample Group call</ h3 >
129
158
< div class ="sample-form ">
130
159
< label for ="name "> Name:</ label >
131
- < input type ="text " id ="name " value ="Twilio ">
160
+ < input type ="text " id ="name " value ="Twilio " required >
161
+ < span class ="error-message " id ="name-error "> This field is required.</ span >
132
162
< label for ="industry "> Industry:</ label >
133
163
< input type ="text " id ="industry " value ="Software ">
134
164
< span class ="error-message " id ="industry-error "> Please enter a valid industry name, using only letters and hyphens.</ span >
@@ -137,6 +167,7 @@ <h3> Sample Group call</h3>
137
167
< span class ="error-message " id ="employees-error "> Please enter a valid number of employees.</ span >
138
168
< label for ="plan "> Plan:</ label >
139
169
< input type ="text " id ="plan " value ="Premium ">
170
+ < span class ="error-message " id ="plan-error "> This field is required.</ span >
140
171
< label for ="totalBilled "> Total Billed:</ label >
141
172
< input type ="text " id ="totalBilled " value ="34000000 ">
142
173
< span class ="error-message " id ="billed-error "> Please enter only numbers in the Total Billed field.</ span >
0 commit comments