On 2005-10-20, Chris Dangerfield <csdangerfield (AT) yahoo (DOT) co.uk> wrote:
Quote:
I am using a script of the web, to validate email addresses. It is good but
lacks 2 important things.
It stops the user from entering an full stop or dash, ie [-] [.] which are
valid in an email.
If anyone has an understanding of the expression below, would you please
help me adapt it so that it allows the 2 characters as above.
Any help much appreciated.
Regards
Chris Dangerfield
var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
var matchArray = form.email.value.match(emailPat);
if (matchArray == null) {
alert("Your email address is incorrectly formated.\nPlease try again (check
the '@' and '.'s in the email address)");
form.email.focus()
return false;
} |
hmmm
/ regex
^ start of string
( first part
\".*\" anything at all between quotes
[A-Za-z]\w* letters follwed by zero or more letters or underscores
} end of first part.
@ at symbol
( second part
\[ bracket
\d{1,3} one to three digits
(\.\d{1,3}) . then one to three digits
{3} - repeated three times
] close bracket
[A-Za-z]\w* name with underscores like above
(\.[A-Za-z]\w*)+ repeatedly dots and more names atleast once
) end of second part
$ end of string
/ end of regex
It's got a number of things wrong with it.
1 - it doesn't allow digits the name part of email
2 - "quoted" names are broken - it allows quotes inside the quotes
3 - support for IP addresses, but the numbers aren't checked
no support for IPV6
4 - it doesn't allow digits in the domain part.
digits are allowed in domain names at the start at the end,
at both ends and in the middle.
for example the following are actual domain names
3com.com - network hardware
jurassic5.com - a band (also sclub7.com)
2for2.com - I have no idea
i18n.org - internationalisation
Bye.
Jasen