Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear monk,

i have problem to make a validation on the email address, in my condition i need to let the user to key in their email account. This is the few restriction for the email address. e.g. aaa@aaa.com, aa.a@aa.com, aa.a@aa.net.uk-- this is a valide email address. the unvalid is like e.g @aaa.com , .aa@aa.com. So my checking is to check, if is a unvalid email address it will prompt a error message on the webpage for the invalid email address. This is the part of code i have done :

if (($aliasmailbox !~ /\@/) or ($aliasmailbox !~ /\./)) { &TaskLog("IMSModifyDetails sub::User's input not sufficient---a\n"); print $query->redirect("/cgi-bin/DisplayModifyDetails.cgi?&ErrorMsg2=I +NPUT3"); exit; } if ($aliasmailbox =~ /^\A[\@|\.]/) { &TaskLog("IMSModifyDetails sub::User's input not sufficient---b\n"); print $query->redirect("/cgi-bin/DisplayModifyDetails.cgi?ErrorMsg2=IN +PUT3"); exit; } *** if (($aliasmailbox =~ /\Z\@/) or ($aliasmailbox =~ /\Z\./)){ &TaskLog("IMSModifyDetails sub::User's input not sufficient---b\n"); print $query->redirect("/cgi-bin/DisplayModifyDetails.cgi?ErrorMsg2=IN +PUT3"); exit; } ***
The line of code which has been remark is to check that at the end position of the string there cannot be "@" or "." e.g. aaa@aa.aa. or aaa@aa.aa@ . any way this code does not work, can anyone fix it for me. from the 3 checking about only validate in one string must have @ and . also in the first position of the string cannot start with "@" or ".",

so how can i make a checking the it muct satisfiy that this validation is true aa.aa@aa.a.com and it become false when the email address is aa.aa@.aa.com--this is wrong after the allias must be charater not dot, any code for this . Can help to see this code which i have done but it totally check all the string where aaa@aa.com--true, else aa.aa@aa.com, aa@aa.aa.uk--- false. so how can i do this, when i need to check that the email address after the "@" cannot be ".". here is the validate code :

if ($aliasmailbox !~ /^.\@$@\.$/)
so what the suggesttion for this and the aa.aa@aa..com this also will return an error.

actually is there anything in perl got the function like Instr in vb, pr what the other way.

Edited 2001/06/28 by Ovid

Replies are listed 'Best First'.
Re: How i can make a good user email cheking
by Abigail (Deacon) on Jun 28, 2001 at 22:25 UTC
    Parsing email addresses is hard. You are mistaken if you think no "," can occur right of the "@" (which "@" do you mean, BTW? There can be many). foo@example (,) . (,) com is a syntactically valid email address.

    There are a few CPAN modules out there that parse email addresses for validation. RFC::RFC822::Address uses Parse::RecDescent to validate addresses to the spec.

    -- Abigail

Re: How i can make a good user email cheking
by lhoward (Vicar) on Jun 28, 2001 at 21:31 UTC