It's easy to adapt the validation function to any type of form input. Simply replace the regular expression and all references to the form field with the appropriate alternatives. For example, validating email addresses is a common application of regular expressions.
Approaches range from simple to complex.
If you want to provide the same functionality for older browsers, you'll have to write a lot of JavaScript code. Now that you understand how to validate state names and email addresses, it's time to tackle phone numbers. Again, there are many ways to approach this project depending on how flexible you want to be. The regular expression below allows for all sorts of possibilities. Finally, it's time to put it all together.