The following regular expression is sometimes used to validate emails:
/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
- The ^ at the start prevents anything from being in front of what we match.
- The $ at the end prevents anything from being after what we match.
- \w stands for any letter, digit, or underscore
- \w+ stands for one or more letters, digits, and underscores
- [\.-] stands for either a period or a -
- [\.-]? stands for there might be one period or one -, or there might be none
- [\.-]?\w+ will match a string that might or might not start with a period or a dash, followed by one or more letters, digits, and underscores
- ([\.-]?\w+)* will match zero or more of the item in parentheses; this means that it might not be present at all, or there may be one or more occurrences of the pattern
- (\.\w{2,3}) will match a period followed by two or three letters, digits, and underscores
See form10.html for an example which uses this regular expression to validate email addresses.