note 34962 added to function.ereg
| From: | dan at reachmultimedia dot com | Date: | Wed, 13 Aug 2003 11:53:50 +0000 |
| Subject: | note 34962 added to function.ereg | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-54075@lists.php.net to get a copy of this message | ||
My first time with RegExps today... learning a lot fo PHP very quickly at the moment so it kind of
caused me some headaches as I'm sure you've all had at some point;)
I was trying to work out an email validation expression of my own so that I could learn how to do
this and understand the code. I found that many of the examples had some problems such as not
including the new(ish) domains such as .museum, .info, etc or forgetting that some people may have
an email address at a sub-domain such as: dan@sub.domain.com or a sub-domain at a foreign tld:
dan@sub.domain.co.uk or dan@sub.domain.com.au.
Took a while but I think I've cracked it!
eregi("^([a-z0-9\._-])+@([a-z0-9\._-])+\.([a-z]{2,6}) (\.[a-z]{2,3})?$", $address)
where $address is the variable holding the email address.
Hope this helps somebody!
----
Manual Page -- http://www.php.net/manual/en/function.ereg.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34962
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34962&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34962&report=yes