The best way to check whether or not an e-mail address is valid is to make sure it is of a valid format. You can do this using regular expressions:
use strict; use warnings; use CGI; my $CGI_obj = CGI->new; my $email = $CGI_obj->param('email'); # or is it params? if ($email =~ m/.*?@.*?\..*?/) { print "This e-mail is valid\n"; } else { print "This is not a valid e-mail\n"; }
You really should check out one of the regular expressions tutorials, i.e.: perlretut Remember that PerlDoc.com and Google are your friends.
Now, you might be saying to yourself, "But how do I know that the e-mail address will work?". The only real way to do that is to send an e-mail to the address you're checking.
The reasons for this are mostly related to efforts at spam prevention. There is some command you can send to port 25 (the email port) if you open up a socket to "ping" it and see if it accepts emails. However, because many networks dont want spammers looking for their e-mail addresses they may disable it. You can look up a domain name to see if you can get an IP address, but this doesn't always work for exotic domains unless your script is very robust.
You can even open up port 25 to send email, and just never complete it, but, again, for spam related purposes if you're not on the network the server isn't guaranteed to respond, even with a "No relaying allowed" message. The other thing to look out for is the email address may be valid but not the original users. So they may be redirecting it to a cache all e-mail (some servers forward all email to root@localhost or webmaster@localhost if the user is not valid). Or they may never read their e-mail.
So, stick with regular expressions. Or you can send out an e-mail to the user asking them to confirm their submission. However, that is a whole nother can of worms and suitable for another thread.
Best Regards,
VautrinIn reply to Re: Re: Re: Create required fields from form
by Vautrin
in thread Create required fields from form
by hcb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |