473,671 Members | 2,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

e-mail validation

I've been looking for a simple way of checking that a string is an e-mail
address. I don't need to check if the address exists, just if the format of
the string matches. There seem to be lots of different methods, can someone
suggest which is the best, with justification. I'm not looking for total
accuracy, I'd much rather let a few false positives through than get any
false negatives.

Many thanks
Jul 16 '05 #1
4 3841
Hello,

On 08/20/2003 07:14 PM, Geoff Soper wrote:
I've been looking for a simple way of checking that a string is an e-mail
address. I don't need to check if the address exists, just if the format of
the string matches. There seem to be lots of different methods, can someone
suggest which is the best, with justification. I'm not looking for total
accuracy, I'd much rather let a few false positives through than get any
false negatives.


You may want to check these classes:
http://www.phpclasses.org/emailvalidation
It has basic regular expression based validation if you do not want to
use the DNS or SMTP server based validation.

http://www.phpclasses.org/formsgeneration
Also regular expression based validation integrated with forms
generation and validation on the client side using Javascript and on the
server side using the class itself.
--

Regards,
Manuel Lemos

Free ready to use OOP components written in PHP
http://www.phpclasses.org/

Jul 16 '05 #2
> I've been looking for a simple way of checking that a string is an e-mail
address. I don't need to check if the address exists, just if the format of the string matches. There seem to be lots of different methods, can someone suggest which is the best, with justification. I'm not looking for total
accuracy, I'd much rather let a few false positives through than get any
false negatives.

you could use the following regexp for a quick solution with preg_match().
regexp:
'/^([\._a-zA-Z0-9-]{1,}){1}@{1}([a-zA-Z0-9-]{1,}){1}\.{1}([a-zA-Z]{1,3}){1}$
/'

yours, dreamguard.
Jul 16 '05 #3

"Geoff Soper" <ne***********@ alphaworks.co.u k> wrote in message
news:3f******** *************@n ews.dial.pipex. com...
I've been looking for a simple way of checking that a string is an e-mail
address. I don't need to check if the address exists, just if the format of the string matches. There seem to be lots of different methods, can someone suggest which is the best, with justification. I'm not looking for total
accuracy, I'd much rather let a few false positives through than get any
false negatives.

Many thanks


This is a PHP version of a JavaScript I found that performs syntax checking
on an email address... There is sufficient remarks in it to let you know the
checks that it does - you just pass it an email address and it will return
"TRUE" or "FALSE" pending if its valid or not. Note, I return my TRUE and
FALSE as a string (ie, inside double quotes) and not as a CONSTANT or INT.

Function (and an example of usage) is below:
function verifyEmail($em ailAddress)
{
// Return "TRUE" if we believe $email is a valid email address,
// else return "FALSE"

// First - make sure it has an @ sign and ensure that each side
// of the @ sign has enough characters to be a valid address
$pos = strpos($emailAd dress, "@");
if ($pos === false) { // note: three equal signs
return("FALSE") ;
}

list($email, $domain)=explod e("@", $emailAddress);
if( (strlen($email) ==0) || (strlen($domain )<2) )
{ return("FALSE") ; }

// make sure the top level of the domain name is no less than
// two characters, and no greater than four characters in order
// to allow .uk, .com, .info, .net etc...
$domains=explod e(".", $domain);

// Make sure the right side of the @ sign (the domain) is made
// up of at least two subdomains (ie @xyz.com and not just @com)
if(count($domai ns)>1)
{ $tld=array_pop( $domains);
// Make sure the top level domain is NOT less than 2 char in length
// and not greater than 4 char in length
if( (strlen($tld)<2 ) || (strlen($tld)>4 ) )
{ return("FALSE") ; }
}
return("TRUE");
}

$e**********@la rge.com;
if(verifyEmail( $example)=="FAL SE")
{
die("Email address $example is NOT valid.");
}
print("<hr>Emai l address $example is believed to be fine and dandy.<hr>");
Jul 16 '05 #4
"Geoff Soper" <ne***********@ alphaworks.co.u k> wrote in message
news:<3f******* **************@ news.dial.pipex .com>...

I've been looking for a simple way of checking that a string is an e-mail
address. I don't need to check if the address exists, just if the format of
the string matches. There seem to be lots of different methods, can someone
suggest which is the best, with justification.


It all depends... For example, do you want to support the "user at
domain dot com" syntax? A slightly less wicked one: do you want to
treat '"Geoff Soper" <ne***********@ alphaworks.co.u k>' as a valid
e-mail address or do you only want to deal with the 'news.20-08-
03@alphaworks.c o.uk' part?

Cheers,
NC
Jul 16 '05 #5

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

Similar topics

1
2647
by: Marlon | last post by:
How can modify this expression \w+(\w+)*@\w+(\w+)*\.\w+(\w+)* to validate multiple email address separator by comma and/or semicolon e.g. someone@somedomain.com;someone2@somedomain.com
4
1797
by: VbUser25 | last post by:
Hi Please suggest i think i am doing something wrong. I am calling fucntion test from another function where i am performing all the validations.I want to validate the email id. this is the main function where i perform all sort of mandatory validation==> if (document.f.repemail.value != ""){ if(test(document.f.repemail.value=false)) {
2
2528
by: AFN | last post by:
Has anyone written any code to verify an email address against an SMTP server? I hear you can see if the address is an alias (catchall) versus a real account. I know you can telnet on port 25 and do a VRFY command, but I think most servers now disable this for security. So is it worthwhile doing any validation against the server? If so, what are the commands you would execute after HELO? Is there a way to see if the address is...
1
1947
by: Jim Dornbush | last post by:
Has anyone seen an updated regex expression from Microsoft for the email validation expression so that single quotes are allowed? I've been using the canned regex for emails, but recently been informed by a customer that the single quote is allowed as part of the email address (Mr. O'Leary). I prefer using the un-modified version from the framework, but will update my local code regardless.
7
3046
by: e_matthes | last post by:
Hello everyone, I've read enough about email validation to know that the only real validation is having a user respond to a confirmation message you've sent them. However, I want to store the address temporarily, so I want to make sure what is entered is safe to work with. I have a basic understanding of regexps, so I could write one that checks for a simple format like: something followed by @ followed by something followed by .....
10
30241
by: ll | last post by:
Hi, I currently am using the following regex in js for email validation, in which the email addresses can be separated by commas or semicolons. The problem, however, lies in that I can type two emails (as a run-on, with no comma or semicolon), and as long as it ends in a three character domain, it is accepted as valid. I wonder if there would be a way to make the comma or semicolon mandatory if a second email address existed? Many...
1
1410
by: vimal.424 | last post by:
Hello guys........ please tell me ............. I want to do email validation like i have a userid entered by user new user.so problem is that i have to do the validation when i'll click on save button b'coz userid should be unique.....
1
1895
by: shwethatj | last post by:
My problem is lik this , I am trying to create a registration form using javascript for a HR website , but i dont know how to provide password validation i.e the password and confirmation password entered by the user should match ...and also email validation i.e email id entered by user should be in correct format ... i know how to do using php but dont know using javascript ... Can anyone help me .... Regards, Shwetha
1
1409
by: curi444 | last post by:
How can i improve email validation in the code below? <?php $con = mysql_connect("localhost", "root", ""); if(isset($_POST)) { $name=$_POST; $address=$_POST; $phno=$_POST;
0
8485
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8828
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8677
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7446
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6238
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5704
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4417
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2062
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.