// Function that checks whether the provided e-mail address is in a valid format (as specified by RFC 822). // // Arguments: // emailAddress - The e-mail address to check. // // Returns: // True if valid, otherwise false. // function CheckEmailValid(emailAddress) { // Remember: .* is greedy by default! // Note that because Javascript insists that we escape backslashes in strings, all backslashes that we want // to put into the regex pattern must actually be doubled up, ie. '\\' will end up being '\' in the actual // regex pattern. This makes for a LOT of backslashes, as we're escaping quite a lot in the actual regex too. var reEmailAddress = new RegExp( '^' + // RFC 822 says e-mail addys consist of any CHAR except specials, SPACE and CTLs. // We also have the @ and . to seperate user or hostnames. // CHAR is ASCII 0-127(0x00-7F). SPACE is ASCII 32(0x20). // CTLs are ASCII 0-31(0x00-1F) and 127(0x7F). Specials are ( ) < > @ , ; : \ " . [ ] // ASCII 127(0x7F) is a DEL control character - prudent to disallow this in an e-mail address. '[^\\x7F\\x80-\\xFF\\x00-\\x20\\(\\)\\<\\>\\@\\,\\;\\:\\\\\\"\\[\\]]+' + // ^ Username... even '(.)@host.com' is ok. '\\@' + // ^ @ '[^\\x7F\\x80-\\xFF\\x00-\\x20\\(\\)\\<\\>\\@\\,\\;\\:\\\\\\"\\[\\]\\.]+' + // ^ Host part 1 (no dots yet): 'blah@(host).com.com'. '\\.' + // ^ . '[^\\x7F\\x80-\\xFF\\x00-\\x20\\(\\)\\<\\>\\@\\,\\;\\:\\\\\\"\\[\\]\\.]+' + '[^\\x7F\\x80-\\xFF\\x00-\\x20\\(\\)\\<\\>\\@\\,\\;\\:\\\\\\"\\[\\]]*' + // ^ Host part 2 (remaining dots allowed): 'blah@host.(com.com)'. '$' ); return reEmailAddress.test(emailAddress); }