A regular expression is a pattern that uses a special syntax to describe the content of a text field. It can be used either to validate that the string contains a valid value or alternatively it can be used to format a value entered so that it matches the specified format.
Here are a couple of regular expressions :
Note that the expressions are fairly long and that in order for them to work correctly they each need to be coded completely on one line (if you select the code in the above box and paste it into a text editor you should get the code set out correctly). These examples define valid formats for email addresses and phone numbers respectively.
The email address regular expression accepts email addresses in the format username @ domain name. There are a couple of other valid email address formats (eg. username @ [ip address]) but this regular expression only accepts the more common format.
The phone number regular expression accepts phone number in both local format (eg. 02 1234 5678 or 123 123 4567) or international format (eg. +61 (0) 2 1234 5678 or +1 123 123 4567). It also accepts an optional extention of up to five digits prefixed by x or ext (eg. 123 123 4567 x89).
Rather than performing a whole series of validations to validate that a given field contains an email address or phone number you can perform one test using the appropriate regular expression instead. For example, the following code could be used with the above regular expressions to validate two fields on your form.
alert(myform.replyemail.value + ' is invalid');
alert(myform.phone.value + ' is invalid');