HighDots Forums  

help with email validation using reg exp

JavaScript discussion (multi-lingual) JavaScript discussion (alt.comp.lang.javascript)


Discuss help with email validation using reg exp in the JavaScript discussion (multi-lingual) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Chris Dangerfield
 
Posts: n/a

Default help with email validation using reg exp - 10-19-2005 , 07:23 PM






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;
}

return true;



Reply With Quote
  #2  
Old   
Jasen Betts
 
Posts: n/a

Default Re: help with email validation using reg exp - 10-21-2005 , 12:47 AM






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

Quote:
or
[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

Quote:
or
[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


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.