473,387 Members | 1,705 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,387 software developers and data experts.

preg_match / valid email address

I need some help with validating an email address. Right now, I am doing this:

function sys_is_valid_email ($s) {
if (preg_match ("/^.+@.+\..+$/", $s)) {
return 1;
} else {
return 0;
}
}

It works great, but it doesn't allow a number at the beginning.

For example
2c***@forme.jom can not be entered
19**@forme.jom can not be entered

but,
co***@forme.jom can be entered
d19**@forme.jom can be entered

Can someone help me with the preg_match?

Thanks,
aaron
Jul 17 '05 #1
10 8135
On Mon, 23 Aug 2004 08:14:23 -0700, aaron wrote:
I need some help with validating an email address. Right now, I am doing this:

function sys_is_valid_email ($s) {
if (preg_match ("/^.+@.+\..+$/", $s)) {
return 1;
} else {
return 0;
}
}

It works great, but it doesn't allow a number at the beginning.

For example
2c***@forme.jom can not be entered
19**@forme.jom can not be entered

but,
co***@forme.jom can be entered
d19**@forme.jom can be entered

Can someone help me with the preg_match?

Thanks,
aaron

It's not perfect (as are none of these solutions) but I have pretty good
results from using:
function check_email($addy, $return_mx_records = false) {
if (empty($addy)) return false;

if (!preg_match('/^[a-zA-Z0-9&\'\.\-_\+]+\@[a-zA-Z0-9.-]+\.+[a-zA-Z]{2,6}$/', $addy)) {
return false;
}

$mx_exists = false;
if (getmxrr(array_pop(explode('@', $addy)), $mx_records)) {
$mx_exists = true;
}

if ($mx_exists) {
return ($return_mx_records) ? $mx_records : true;
} else {
return false;
}
}
This also checks for existence of an MX record for the user-given domain.
If none is found, it's an invalid address.

Your example is using regex for pretty much useless matching, you may
aswell have used:
if (strstr('@', $address) and (strstr('.', $address)) {
/* Mail address is valid (but really could be anything */
} else {
/* Would only reach here if there was no @ or . chars, so
* '................foo@/$£%££djuid....................invalid'
* is a valid address? ;)
*/
}
HTH.

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/

Jul 17 '05 #2
aaron wrote:
I need some help with validating an email address. Right now, I am doing this:

function sys_is_valid_email ($s) {
if (preg_match ("/^.+@.+\..+$/", $s)) {
return 1;
} else {
return 0;
}
}

It works great, but it doesn't allow a number at the beginning.

For example
2c***@forme.jom can not be entered
19**@forme.jom can not be entered

but,
co***@forme.jom can be entered
d19**@forme.jom can be entered

Can someone help me with the preg_match?


I've been having good results with this:

/([a-z][a-z0-9_.-\/]*@[^\s\"\)\?<>]+\.[a-z]{2,6})/i

Some of the stuff in there is so you can have something like:

"My email address is me@example.com." or "Email me (me@example.com) for
more info."

and you will only get the "me@example.com" part.

--
Justin Koivisto - sp**@koivi.com
http://www.koivi.com
Jul 17 '05 #3
"aaron" wrote:
I need some help with validating an email address. Right now, I am
doing this:

function sys_is_valid_email ($s) {
if (preg_match ("/^.+@.+\..+$/", $s)) {
return 1;
} else {
return 0;
}
}

It works great, but it doesn’t allow a number at the beginning.

For example
2c***@forme.jom can not be entered
19**@forme.jom can not be entered

but,
co***@forme.jom can be entered
d19**@forme.jom can be entered

Can someone help me with the preg_match?

Thanks,
aaron

See this thread:
http://dbforumz.com/PHP-Email-Valida...ict140155.html

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-preg_mat...ict142346.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=476226
Jul 17 '05 #4
steve <Us************@dbForumz.com> wrote in message news:<41********@news.athenanews.com>...
"aaron" wrote:
> I need some help with validating an email address. Right now, I am
> doing this:
>
> function sys_is_valid_email ($s) {
> if (preg_match ("/^.+@.+\..+$/", $s)) {
> return 1;
> } else {

return 0;
> }
> }
>
> It works great, but it doesn?t allow a number at the beginning.
>
> For example
> 2c***@forme.jom can not be entered
> 19**@forme.jom can not be entered
>
> but,
> co***@forme.jom can be entered
> d19**@forme.jom can be entered
>
> Can someone help me with the preg_match?
>
> Thanks,
> aaron

See this thread:
http://dbforumz.com/PHP-Email-Valida...ict140155.html


If you use the one suggested above, it works great as long as you
don't have an email address like this: 22*******@asdf.com.

There is a person I know that tried to sign up online with an email
address starting off with 5 numbers. That the link above...
preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)
*?[a-z]+$/is',
$email) ... doesn't let you have 5 numbers.

I have know idea why someone would have that many numbers. Any other
suggestions?
Jul 17 '05 #5
aaron wrote:
steve <Us************@dbForumz.com> wrote in message news:<41********@news.athenanews.com>...
"aaron" wrote:
> I need some help with validating an email address. Right now, I am
> doing this:
>
> function sys_is_valid_email ($s) {
> if (preg_match ("/^.+@.+\..+$/", $s)) {
> return 1;
> } else {

return 0;
> }
> }
>
> It works great, but it doesn?t allow a number at the beginning.
>
> For example
> 2c***@forme.jom can not be entered
> 19**@forme.jom can not be entered
>
> but,
> co***@forme.jom can be entered
> d19**@forme.jom can be entered
>
> Can someone help me with the preg_match?
>
> Thanks,
> aaron

See this thread:
http://dbforumz.com/PHP-Email-Valida...ict140155.html

If you use the one suggested above, it works great as long as you
don't have an email address like this: 22*******@asdf.com.

There is a person I know that tried to sign up online with an email
address starting off with 5 numbers. That the link above...
preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)
*?[a-z]+$/is',
$email) ... doesn't let you have 5 numbers.

I have know idea why someone would have that many numbers. Any other
suggestions?


Don't all valid email address have to start with a letter first? IIRC,
that was stated in the RFC.

--
Justin Koivisto - sp**@koivi.com
http://www.koivi.com
Jul 17 '05 #6
On 24 Aug 2004 08:01:44 -0700, re*********@msn.com (aaron) wrote:
If you use the one suggested above, it works great as long as you
don't have an email address like this: 22*******@asdf.com.

There is a person I know that tried to sign up online with an email
address starting off with 5 numbers. That the link above...
preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)
*?[a-z]+$/is',
$email) ... doesn't let you have 5 numbers.

I have know idea why someone would have that many numbers. Any other
suggestions?


People using a university e-mail account will often have an address
comprising their student id which could be six or seven numbers.

--
David ( @priz.co.uk )
Jul 17 '05 #7
Justin Koivisto <sp**@koivi.com> wrote in message news:<2a*****************@news7.onvoy.net>...
aaron wrote:
steve <Us************@dbForumz.com> wrote in message news:<41********@news.athenanews.com>...
"aaron" wrote:
> I need some help with validating an email address. Right now, I am
> doing this:
>
> function sys_is_valid_email ($s) {
> if (preg_match ("/^.+@.+\..+$/", $s)) {
> return 1;
> } else { return 0; > }
> }
>
> It works great, but it doesn?t allow a number at the beginning.
>
> For example
> 2c***@forme.jom can not be entered
> 19**@forme.jom can not be entered
>
> but,
> co***@forme.jom can be entered
> d19**@forme.jom can be entered
>
> Can someone help me with the preg_match?
>
> Thanks,
> aaron
See this thread:
http://dbforumz.com/PHP-Email-Valida...ict140155.html

If you use the one suggested above, it works great as long as you
don't have an email address like this: 22*******@asdf.com.

There is a person I know that tried to sign up online with an email
address starting off with 5 numbers. That the link above...
preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)
*?[a-z]+$/is',
$email) ... doesn't let you have 5 numbers.

I have know idea why someone would have that many numbers. Any other
suggestions?


Don't all valid email address have to start with a letter first? IIRC,
that was stated in the RFC.


I thought so, but I know for a fact that MSN/Hotmail lets you use
numbers at the beginning.

Wow, does that mean Microsoft would manipulate a standard? That
doesn't sound like Microsoft. :)
Jul 17 '05 #8
re*********@msn.com (aaron) wrote in message news:<dd**************************@posting.google. com>...
function sys_is_valid_email ($s) {
if (preg_match ("/^.+@.+\..+$/", $s)) {
return 1;
} else {
return 0;
}
}

It works great, but it doesn't allow a number at the beginning.


Try <http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html>

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
Jul 17 '05 #9
ng**********@rediffmail.com (R. Rajesh Jeba Anbiah) wrote in message news:<ab**************************@posting.google. com>...
re*********@msn.com (aaron) wrote in message news:<dd**************************@posting.google. com>...
function sys_is_valid_email ($s) {
if (preg_match ("/^.+@.+\..+$/", $s)) {
return 1;
} else {

return 0;
}
}

It works great, but it doesn't allow a number at the beginning.


Try <http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html>


Pardon my ignorance, but does that mean I would have to call a perl
script from PHP to validate?
Jul 17 '05 #10
re*********@msn.com (aaron) wrote in message news:<dd**************************@posting.google. com>...
<snip>
Try <http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html>


Pardon my ignorance, but does that mean I would have to call a perl
script from PHP to validate?


I didn't mean that. Just grab the logic and transform it into a PHP script.

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
Jul 17 '05 #11

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

Similar topics

16
by: siliconmike | last post by:
Hi, I'm looking for a reliable script that would connect to a host and somehow determine whether an email address is valid. since getmxrr() only gets the mx records.. Links/pointers ? Mike
11
by: Phil Amey | last post by:
In a web based form I am able to make sure that there is text in an input field but I want to force the user into inputting a valid email address, one that has @ in the address How can I modify...
2
by: charleswesley | last post by:
I find myself regularly needing to validate user input as either a) numeric only or b) valid email address format (user@domain.tld) I am assuming that there are regular expressions that can be...
3
by: satees | last post by:
Hi, I need to check the given email address is valid or not within the specified server. For eg: If i give the address xyz@yahoo.com, the code need to check with the yahoo server whether the id...
1
by: somaskarthic | last post by:
Hi How can i check whether the email address is valid one ? If that id exist , mail would be sent successfully . Incase if the sending mail to an id fails , how can i identify the send mail...
2
by: e_matthes | last post by:
Hello everyone, I am about to implement an authentication system on the site I am building. I don't care much what users choose for their username and password, but I want to verify that users...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.