|
82 | 82 | cityField.style.outline = "";
|
83 | 83 | }
|
84 | 84 |
|
| 85 | +// Regular expression check for city name |
| 86 | +var stateRegex = /^[A-Z]{2}$/; |
| 87 | +if (!stateRegex.test(state)) { |
| 88 | + const stateError = document.getElementById("state-error"); |
| 89 | + stateError.style.display = "block"; |
| 90 | + const stateField = document.getElementById("state"); |
| 91 | + stateField.style.outline = "2px solid red"; |
| 92 | + errors.push("State is invalid"); |
| 93 | +} else { |
| 94 | + const stateError = document.getElementById("state-error") |
| 95 | + stateError.style.display = "none"; |
| 96 | + const stateField = document.getElementById("state") |
| 97 | + stateField.style.outline = ""; |
| 98 | +} |
| 99 | + |
85 | 100 | // Regular expression check for postcode
|
86 | 101 | var postcodeRegex = /^\d{5}$/;
|
87 | 102 | if (!postcodeRegex.test(postcode)) {
|
@@ -183,6 +198,7 @@ <h4> Sample Identify </h4>
|
183 | 198 | <span class="error-message" id="city-error">Please enter a valid city name in the 'City' field.</span>
|
184 | 199 | <label for="state">State:</label>
|
185 | 200 | <input type="text" id="state" value="TN">
|
| 201 | + <span class="error-message" id="state-error">Please enter a valid two-letter state code in all caps, like 'CA' for California.</span> |
186 | 202 | <label for="postcode">Zip Code:</label>
|
187 | 203 | <input type="text" id="postcode" value="37215">
|
188 | 204 | <span class="error-message" id="postcode-error">Please enter a valid five-digit zip code.</span>
|
|
0 commit comments