If your programs require that the end users enter an email,
you have to make sure it is being input in the correct
format. Especially if this email is going to be displayed
or used for contact. If the email is not entered in the format
someone@somewhere.ext, it won't work.
This utility takes away the risk that an email will be formatted
incorrectly by the person inputting it. This utility will check the
format of the email and then return true if it is correct or false
if it is not formatted correctly. Thus, you can use it as a conditional.
For example, I use it as a test where if the email address is formatted
correctly, the program proceeds and if it is not formatted correctly, the
program halts and prints out an error message or input box for them to
re-enter it:
if(&check_email($FORM{'email'})) {
Email properly formatted,
proceed with program.
This proceed can be a few
lines long or hundreds
of lines long, as in a
registration for a service.
} else {
Email not properly formatted,
print warning/error page.
}
Here is how you use this utility:
Either cut and paste this subroutine into your own script or
"require" this file by placing it in the same directory as your
script and placing the following line anywhere before the
subroutine is first called:
require 'check_email.pl';
Now you are ready to use it. The subroutine needs one parameter
passed to it. This is the email address you want the format checked for.
Here are some of the mistakes that this utility will catch and return
false for:
- If the form is submitted with NO email address, it returns false as the email address is mandatory
- somewhere@something
- somewhere@@something
- somewhere@something..com
- somewhere.@something.com
- somewhere@s@omething.com
NOTE: This subroutine does not check to see if the email address
actually exists, it only checks to see if the email address is in
the proper format.
|