473,395 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

function to validate email?

Hello, Could someone point me to a PHP 4 function that validates that
an email address is of the right form?

Thanks for your help, - Dave

Oct 17 '05 #1
2 1631
"la***********@zipmail.com" wrote:
Hello, Could someone point me to a PHP 4 function that validates that
an email address is of the right form?

Thanks for your help, - Dave


This is what I use:

function checkEmailSyntax($em)
{
$re_bad = '/(@)|(\.\.)|(^\.)|(\.$)/';
$re_ok1 = '/^[^\x00-\x1f <>\x22\x7f]+$/';
$re_ok2 = '/^([A-Za-z0-9\-_]+\.){1,5}[A-Za-z]{2,5}$/';

$t_split = explode("@",$em);

if (count($t_split) == 2) {
$t_name = $t_split[0];
$t_domain = $t_split[1];

if ( !preg_match($re_bad, $t_name) &&
preg_match($re_ok1, $t_name) &&
!preg_match($re_bad, $t_domain) &&
preg_match($re_ok2, $t_domain) ) {
return true;
}
}
return false;
}

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/
Oct 17 '05 #2
Philip Ronan wrote:
"la***********@zipmail.com" wrote:

Hello, Could someone point me to a PHP 4 function that validates that
an email address is of the right form?

Thanks for your help, - Dave

This is what I use:

function checkEmailSyntax($em)[snip]


dude,

very cool, probably the nicest i've seen. i'm going to test it out on
the form i'm currently building. here's the one i wrote and have been
using, just for laughs:

/*Missing or incorrectly formatted email address*/
if(empty($senderemail))
{
$errormessage.="Please Provide Your E-Mail Address<br>";
}
else if
(!eregi('^[-a-zA-Z0-9_\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$',$senderemail))
{
$errormessage.="Please Provide an E-mail Address in a Valid Format<br>";
}
Oct 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jon | last post by:
Hi, I have a form. I have the code, below, to check for certain compulasry fields. The Submit button has: onClick="validate(this.form)" My problem is that the warnings come up fine, but the...
5
by: Seeker | last post by:
Newbie question here... I have a form with some radio buttons. To verify that at least one of the buttons was chosen I use the following code ("f" is my form object) : var btnChosen; for...
2
by: Fabri | last post by:
I would like to ask you the following: I use Macromedia Dreamweaver as an editor for HTML and Js. It also writes some js functions to simply validate forms. I always used it with no bugs. ...
3
by: Claire | last post by:
I have a large record with many enumerated fields. The record is stored in a file and the fields have to be extracted. I validate the data as it's read, but there's so many tests similar to the...
1
by: ApexData | last post by:
Hello I have an UNBOUND textbox Text1 that I want to validate in code. I want to lock the user into the field until Valid Data is entered. I created the following Function: Private Function...
5
by: eyoung | last post by:
I have a function to check a string to make sure it is 6 digites using the trigger onBlur="CkFrmt(this)" Problem is I've got 4 fields in a row...if I enter a wrong number in the first and hit tab...
2
by: cryme | last post by:
Im having a minor, simple problem. Basicly i have two different scripts they both work separately and together but just that both executes at the same time. On my html page i have a form, one of...
24
by: Mike Hofer | last post by:
Please forgive the cross-post to multiple forums. I did it intentionally, but I *think* it was appropriate given the nature of my question. I'm working on an open source code library to help...
4
by: istillshine | last post by:
I have a function foo, shown below. Is it a good idea to test each argument against my assumption? I think it is safer. However, I notice that people usually don't test the validity of...
2
by: phpentrylevel | last post by:
hello i am a newbie to Javascript with a in depth background of PHP i have a simple script that replaces missing images when the webpage loads but i just cant get it to validate in JLint as my...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.