Re: Checking and email address
If you want to see if a variable contains a @, do what the other suggested. If you want to see if you have (at least) a well formed email address (with optional MX host checking) look at Email::Valid. Cheers, Kevin On Mon, Apr 15, 2002 at 11:58:11PM -0400, Daniel Falkenberg ([EMAIL PROTECTED]) said something similar to: > Hello All, > > How would I go about checking to see if a variable contains an @ symbol? > > $email = "[EMAIL PROTECTED]"; > > if ($email ne "@" || $email eq "") { > print "Please make sure your type your email address in correctly"; > } else { > print "All is OK"; > } > > Thx, > > Dan > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] -- [Writing CGI Applications with Perl - http://perlcgi-book.com] I keep looking for the "Crash after viewing X pages" settings in Netscape, but I just can't find it. -- me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Checking and email address
On 4/15/02 10:38 PM, Timothy Johnson <[EMAIL PROTECTED]> wrote: > I think the preferred way to do a negative match is with the !~ operator. > > if( $email !~ /@/ ) > > at this point you don't really need to check if $email eq "", because if it > does it will not have an @ in it. > > I'm not sure, but you might also have to escape the @. There's always unless ($email =~ /\@/){ # invalid } else{ # valid. } Of course, that's sort of backwards logic. Regexes do interpolate, so it certainly makes sense to escape the @. I'll point out now that there was a discussion a while back on either [EMAIL PROTECTED], [EMAIL PROTECTED], or [EMAIL PROTECTED] regarding the validation of email addresses, and why it was basically impossible. The best way to validate an email address remains to send an email to the supplied address with a required activation code or the like. That way the user can't use the service until they get their activation code, which is the mailbox of the email address they specified. I'm not sure how valid that is for your situation, though. On 4/15/02 8:50 PM, bob ackerman <[EMAIL PROTECTED]> wrote: > ...regilar expressions... s/regilar/regular/; :P -- Michael -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Checking and email address
I think the preferred way to do a negative match is with the !~ operator. if( $email !~ /@/ ) at this point you don't really need to check if $email eq "", because if it does it will not have an @ in it. I'm not sure, but you might also have to escape the @. -Original Message- From: bob ackerman To: [EMAIL PROTECTED] Sent: 4/15/02 8:50 PM Subject: Re: Checking and email address On Monday, April 15, 2002, at 08:58 PM, Daniel Falkenberg wrote: > Hello All, > > How would I go about checking to see if a variable contains an @ symbol? > > $email = "[EMAIL PROTECTED]"; > > if ($email ne "@" || $email eq "") { > print "Please make sure your type your email address in correctly"; > } else { > print "All is OK"; > } > > Thx, > > Dan well, i got the sense wrong on my original answer. try if ( !($email=~/@/) or $email eq '') . regilar expressions are an important part of perl. you might want to look into it. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Checking and email address
On Monday, April 15, 2002, at 08:58 PM, Daniel Falkenberg wrote: > Hello All, > > How would I go about checking to see if a variable contains an @ symbol? > > $email = "[EMAIL PROTECTED]"; > > if ($email ne "@" || $email eq "") { > print "Please make sure your type your email address in correctly"; > } else { > print "All is OK"; > } > > Thx, > > Dan well, i got the sense wrong on my original answer. try if ( !($email=~/@/) or $email eq '') regilar expressions are an important part of perl. you might want to look into it. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Checking and email address
On Monday, April 15, 2002, at 08:58 PM, Daniel Falkenberg wrote: > Hello All, > > How would I go about checking to see if a variable contains an @ symbol? > > $email = "[EMAIL PROTECTED]"; > > if ($email ne "@" || $email eq "") { > print "Please make sure your type your email address in correctly"; > } else { > print "All is OK"; > } > > Thx, > > Dan > if ($email =~ /@/ or $email eq '') -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]