Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Specific E-Mail Validation Script

Reply
Thread Tools

Specific E-Mail Validation Script

 
 
ibizara
Guest
Posts: n/a
 
      01-23-2008
Please could anyone help I need a validation script on and input field
email to include/exclude the below?
If it is even possible even??
Many Thanks in advanced, Regards, Jason

-----------------------------------------------------------------------------

(Note " * " is NOT a wildcard in the instances below)

include:
a-Z 0-1 * _ - @ a-Z 0-1 _ - . a-Z 0-1

exclude:
*@hsbc.com
*@barclays.com
*@hotmail.com

-----------------------------------------------------------------------------

if (theForm.email.value == "")
{
alert("Please enter a valid email");
theForm.email.focus();
return (false);
}

var checkemail = "@.";
var checkStr = theForm.email.value;
var emailValid = false;
var emailAt = false;
var emailPeriod = false;
for (i = 0; i < checkStr.length; i++)
{
ch = checkStr.charAt(i);
for (j = 0; j < checkemail.length; j++)
{
if (ch == checkemail.charAt(j) && ch == "@")
emailAt = true;
if (ch == checkemail.charAt(j) && ch == ".")
emailPeriod = true;
if (emailAt && emailPeriod)
break;
if (j == checkemail.length)
break;
}

if (emailAt && emailPeriod)
{
emailValid = true
break;
}
}
if (!emailValid)
{
alert("Please enter a valid email");
theForm.email.focus();
return (false);
}

-----------------------------------------------------------------------------

<form name="whitelist" method="post" action="submit.php">
<input name="email" type="text" id="email"
onblur="lowerCase(this.id)">
<i>(E-Mail Removed) (*@company.com = anything)</i><br>
<i>Please do <font color="red">NOT</font> add <u>*@hotmail.com</u> ,
only to company domains eg. <u>*@scruttonbland.co.uk</u></i><br>
<i>Also please <font color="red">exclude</font> Bank email addresses
(@rbs.co.uk @barclays.co.uk @lloydstsb.com @hsbc.co.uk @natwest.com)</
i><br>
<input name="submit" type="submit" id="submit" value="Submit">
 
Reply With Quote
 
 
 
 
Dr J R Stockton
Guest
Posts: n/a
 
      01-23-2008
In comp.lang.javascript message <a10b516c-4a7e-42ec-a344-ce264efaa668@u1
0g2000prn.googlegroups.com>, Wed, 23 Jan 2008 09:13:17, ibizara
<(E-Mail Removed)> posted:
>Please could anyone help I need a validation script on and input field
>email to include/exclude the below?


You are wasting your time doing it that way. Invest a little time in
learning the beginnings of RegExps, and you will soon profit.

<URL:http://www.merlyn.demon.co.uk/js-valid.htm>

Disregarding for the moment your objection to banks, it is very
difficult for the amateur to write something which passes ALL valid
address forms and rejects at least most invalid ones. NEVER over-
validate E-addresses that you are not yourself creating; but when
creating it is reasonable to be restrictive.

Spam = /.*@(hsbc|barclays|hotmail)\.com$/.test(Addr)
should detect the forms you indicated.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
Reply With Quote
 
 
 
 
ibizara
Guest
Posts: n/a
 
      01-24-2008
> >Please could anyone help I need a validation script on and input field
> >email to include/exclude the below?

>
> You are wasting your time doing it that way. *Invest a little time in
> learning the beginnings of RegExps, and you will soon profit.


As it does seem pretty difficult to get it just right i'm going to try
searching a few places and my result I will post here.

Might try...

Check whole email and accept if they have

a-Z 0-1 * _ - @ .

Check whole email, Must have the below

@ .

Thanks for your reply.

J
 
Reply With Quote
 
ibizara
Guest
Posts: n/a
 
      01-24-2008
On 24 Jan, 10:24, ibizara <(E-Mail Removed)> wrote:
> > >Please could anyone help I need a validation script on an input field
> > >email to include/exclude the below?

>
> > You are wasting your time doing it that way. *Invest a little time in
> > learning the beginnings of RegExps, and you will soon profit.

>
> As it does seem pretty difficult to get it just right i'm going to try
> searching a few places and my result I will post here.
>
> Might try...
>
> Check whole email and accept if they have
>
> a-Z 0-1 * _ - @ .
>
> Check whole email, Must have the below
>
> @ .


Achieved what I needed but in PHP rather than JavaScipt

<?php
// Receiving variables
@$email = addslashes($_POST['email']);

if (! ereg('^[*a-z\'0-9]+([._-][*a-z\'0-9]+)*@([a-z0-9]+([._-][a-
z0-9]+))+$', $email)){
include_once("error.inc");
die();
}

if(preg_match('/\*@(hotmail|rbs|barclays|lloydstsb|hsbc|natwest)\. (com|
co\.uk)$/i',$email)){
include_once("not_allowed.inc");
die();
}
?>

But if anyone wants to help convert the above to JS... ?

J




 
Reply With Quote
 
Dr J R Stockton
Guest
Posts: n/a
 
      01-24-2008
In comp.lang.javascript message <a10b516c-4a7e-42ec-a344-ce264efaa668@u1
0g2000prn.googlegroups.com>, Wed, 23 Jan 2008 09:13:17, ibizara
<(E-Mail Removed)> posted:
>Please could anyone help I need a validation script on and input field
>email to include/exclude the below?


You are wasting your time doing it that way. Invest the time in
learning RegExps first.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      01-29-2008
Jeremy J Starcher wrote:
> On Wed, 23 Jan 2008 09:13:17 -0800, ibizara wrote:
>> Please could anyone help I need a validation script on and input field
>> email to include/exclude the below?
>> If it is even possible even??

>
> You /really/ are best not trying to validate an email address with
> regular expressions. I assure you, they are far more complex than you
> think.


They are not. I have derived and posted a very short RegExp based on the
productions of RFC2822, section 3.4.1., here before.

> If you really want the regular expression to check email addresses,
> see here. I've not tested it under JS, but it *should* work.


It should not, as ECMAScript Regular Expressions are not based on
Perl-compatible Regular Expressions (PCRE), whereas e.g. PHP Regular
Expressions are.

> (Warning: Perl link -- May lead to blindness)
> <URL: http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html >


This oft-cited code that has always been outdated (RFC2822 obsoleted RFC822
in 2001-04 CE, the code is dated 2002-04-13 CE) does not check for
e-mail-addresses, it checks for outdated address headers. It's 2008 CE now;
I wished people would finally stop citing it.


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XML parsing problem finding a specific element in a specific place mazdotnet ASP .Net 2 10-02-2009 10:07 AM
Parsing DOM to search specific tags with specific custom attribute William FERRERES Javascript 7 07-09-2007 08:11 PM
Is ViwState Page-Specific or UserControl-Specific =?Utf-8?B?SmF2?= ASP .Net 2 08-16-2006 09:30 PM
redirect traffic on specific ip to specific interface mimiseh Cisco 3 06-05-2005 09:14 PM
How do you make sure a frameset is loaded? I'm trying to open a frameset in a new window which shows a specific html page in a specific frame ck388 Javascript 1 09-24-2003 08:32 PM



Advertisments