Here is a place to post useful and reusable code that you would like to share. Keep it trimmed, only the necessar parts, and if need be, give a description of how to integrate it into a project(and even an example if you can), and keep the code in the [ code] and [/ code] tags(without spaces. :P). Be sure to include the language. :D
Here's one to start:
It's a simple email validity checking subroutine written in
Perl, which uses a regular expression to check and make sure that it resembles a valid email.
Code:
sub checkemail {
my $email = shift;
my @exts = ("com", "org", "net", "info");
foreach (@exts) {
if ($email =~ /^(.+)[@](.+[.]$_)/) {
print ("Valid email address entered. ($email)\n");
print ("Username is $1.\n");
print ("Hostname is $2.\n");
exit (0);
}
}
print ("Please enter a valid email address.\n");
}
An example of how to use it would be:
Code:
sub checkemail {
my $email = shift;
my @exts = ("com", "org", "net", "info");
foreach (@exts) {
if ($email =~ /^(.+)[@](.+[.]$_)/) {
print ("Valid email address entered. ($email)\n");
print ("Username is $1.\n");
print ("Hostname is $2.\n");
exit (0);
}
}
print ("Please enter a valid email address.\n");
}
my $em = $ARGV[0];
checkemail($em);
Enjoy. :D
Note: Spam this thread and what will follow will be the most violent
e-beating of a person ever recorded in history. :D