|
67 | 67 | loginsField.style.outline = "";
|
68 | 68 | }
|
69 | 69 |
|
| 70 | +// Regular expression check for street |
| 71 | +var streetRegex = /^\d+\s[A-z]+\s[A-z]+/; |
| 72 | +if (!streetRegex.test(street)) { |
| 73 | + const streetError = document.getElementById("street-error"); |
| 74 | + streetError.style.display = "block"; |
| 75 | + const streetField = document.getElementById("street"); |
| 76 | + streetField.style.outline = "2px solid red"; |
| 77 | + errors.push("Street is invalid"); |
| 78 | +} else { |
| 79 | + const streetError = document.getElementById("street-error"); |
| 80 | + streetError.style.display = "none"; |
| 81 | + const streetField = document.getElementById("street"); |
| 82 | + streetField.style.outline = ""; |
| 83 | +} |
| 84 | + |
70 | 85 | // Regular expression check for city name
|
71 | 86 | var cityRegex = /^[A-Za-z\s-']+$/;
|
72 | 87 | if (!cityRegex.test(city)) {
|
|
97 | 112 | stateField.style.outline = "";
|
98 | 113 | }
|
99 | 114 |
|
| 115 | +// Regular expression check for country |
| 116 | +var countryRegex = /^[A-Z]{2}$/; |
| 117 | +if (!countryRegex.test(country)) { |
| 118 | + const countryError = document.getElementById("country-error"); |
| 119 | + countryError.style.display = "block"; |
| 120 | + const countryField = document.getElementById("country"); |
| 121 | + countryField.style.outline = "2px solid red"; |
| 122 | + errors.push("Country is invalid"); |
| 123 | +} else { |
| 124 | + const countryError = document.getElementById("country-error"); |
| 125 | + countryError.style.display = "none"; |
| 126 | + const countryField = document.getElementById("country"); |
| 127 | + countryField.style.outline = ""; |
| 128 | +} |
| 129 | + |
100 | 130 | // Regular expression check for postcode
|
101 | 131 | var postcodeRegex = /^\d{5}$/;
|
102 | 132 | if (!postcodeRegex.test(postcode)) {
|
|
181 | 211 | <h4> Sample Identify </h4>
|
182 | 212 | <div class="sample-form">
|
183 | 213 | <label for="name">Name:</label>
|
184 |
| - <input type="text" id="name" value="Dolly Parton"> |
| 214 | + <input type="text" id="name" value="John Smith"> |
185 | 215 | <span class="error-message" id="name-error">Please enter your name.</span>
|
186 | 216 | <label for="email">Email:</label>
|
187 |
| - <input type="text" id="email" value="dollyparton@fake-email.com"> |
| 217 | + <input type="text" id="email" value="john-smith@gmail.com"> |
188 | 218 | <span class="error-message" id="email-error">Please enter a valid email address.</span>
|
189 | 219 | <label for="plan">Plan:</label>
|
190 | 220 | <input type="text" id="plan" value="Premium">
|
191 | 221 | <label for="logins">Logins:</label>
|
192 | 222 | <input type="text" id="logins" value="2">
|
193 | 223 | <span class="error-message" id="logins-error">Please enter only numbers in the 'Logins' field.</span>
|
194 | 224 | <label for="street">Street:</label>
|
195 |
| - <input type="text" id="street" value="P.O. Box 150307"> |
| 225 | + <input type="text" id="street" value="101 Spear Street"> |
| 226 | + <span class="error-message" id="street-error">Please enter a valid street address, including the street name and number.</span> |
196 | 227 | <label for="city">City:</label>
|
197 |
| - <input type="text" id="city" value="Nashville"> |
| 228 | + <input type="text" id="city" value="San Francisco"> |
198 | 229 | <span class="error-message" id="city-error">Please enter a valid city name in the 'City' field.</span>
|
199 | 230 | <label for="state">State:</label>
|
200 |
| - <input type="text" id="state" value="TN"> |
| 231 | + <input type="text" id="state" value="CA"> |
201 | 232 | <span class="error-message" id="state-error">Please enter a valid two-letter state code in all caps, like 'CA' for California.</span>
|
202 | 233 | <label for="postcode">Zip Code:</label>
|
203 |
| - <input type="text" id="postcode" value="37215"> |
| 234 | + <input type="text" id="postcode" value="94105"> |
204 | 235 | <span class="error-message" id="postcode-error">Please enter a valid five-digit zip code.</span>
|
205 | 236 | <label for="country">Country:</label>
|
206 |
| - <input type="text" id="country" value="USA"> |
| 237 | + <input type="text" id="country" value="US"> |
| 238 | + <span class="error-message" id="country-error">Please enter a two-letter country code in all caps, like 'US' for United States.</span> |
207 | 239 | <input type="submit" class="button button-hollow" id="submit" onclick="showMessage(); showOutput()" value="See a sample identify call">
|
208 | 240 | </div>
|
209 | 241 | </div>
|
|
0 commit comments