JavaScript Form Validation With Regular Expressions
A scholar wants to write a really popular book, but is not sure what topic would be the most popular. You are invited to develop a web page (with an embedded form) for him to collect readers’ opinions to help decide the most popular subject. The following items shall be included in your form: reader’s name, gender, age, education (highest degree earned via a menu), home state (limit to US only), occupation, favorite hobby, contact phone, email address, the subject (or book title) that the reader would recommend to the scholar, and a support message that explains the subject and gives reasons why the subject is recommended.
The following guidelines/requirements must be followed:
-
You must choose a right type of widget for each of the above items to be included. For example, a menu of state names shall be provided for the readers to choose from.
-
For most (if not all) of the input items, based on their nature you must design a proper way to validate user’s input using the event programming facility of JavaScript (using events onblur and onchange). You shall try to give the maximum flexibility and convenience to your users, e.g., with the phone number’s input, you should allow all the following formats, 618 453 6046, or 618 4536046, or (618)4536046, or 618 453-6046, 618-453-6046, or, 453 6046, or 453-6046, etc. When the region code is missing, your script shall automatically fill in 618 as the default region code, and then redisplay the phone using this standard form: 618-453-6046.
-
Make your design look nice and professional.