24, July 2008

Validate email adresses - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: Validate email adresses
« previous next »
Pages: [1] Print

Author Topic: Validate email adresses  (Read 1306 times)
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7975
40807 credits
Members referred : 3



« on: Sep 21, 2005, 04:30:32 PM »

I've just found this nice function that helps you validate the emai adresses that the users give you.

Code:
<?php
function valid_email($email) {
  
$regexp="/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i";
  if ( !
preg_match($regexp$email) ) {

       return 
false;
  }
  return 
true;

?>


Just use a code like this to validate the mail adress that the user gave you :

Code:
<?php

if ( valid_email $mail ) )
{
     
mai ( .............. );
}
else
{
     echo 
'The mail adress ' $mail ' is not valid. Try another one ';
}
?>


Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Novice Spammer
***
Posts: 100
103 credits
Members referred : 0



« Reply #1 on: Sep 27, 2005, 11:56:35 AM »

I find that javascript is easier, but I am forced to use PHP because some people dont have JS enabled.
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1517
6803 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #2 on: Oct 03, 2005, 06:00:14 PM »

You will be suprised how many times I disable JS and forms let me enter what I like... it is always a good idea to have server-side check in addition or instead of client-side.


Last blog : Site of the Month - August 2007
I wish I was an Oscar winner
**
Posts: 86
247 credits
Members referred : 0



« Reply #3 on: Oct 03, 2005, 06:11:33 PM »

You will be suprised how many times I disable JS and forms let me enter what I like... it is always a good idea to have server-side check in addition or instead of client-side.

I agree. With server side scripting you'll never worry what software your visitor uses
Cyberpunk Wannabe
*
Gender: Male
Posts: 43
280 credits
Members referred : 0


Lolo means Grandpa in the Philippines!


« Reply #4 on: May 07, 2007, 11:41:03 AM »


Quote
 $regexp="/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i";
 $regexp="/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*){2,}\\.[a-z]{2,}$/i";


Is a one letter 2nd level domain legal?

Can anyone give an example of a one letter 2nd level domain?

I can find www.7T.NET Visit through proxy (2 letters in the 2nd level).
and
www.JP.TO Visit through proxy (two letters in the second level).

Is there anything like a "c.cc" domain?

If all 2nd levels are at lease 2 letters, wouldn't the second example in the above quote (with blue {2,} 2 or more letters) be better than the first (with red + 1 or more letters)?

I don't know all the domain rules, just never saw a single letter 2nd level domain.

Any comment?

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7975
40807 credits
Members referred : 3



« Reply #5 on: May 07, 2007, 01:57:18 PM »

I know of 2 letter domains (eg. in.gr) but I am not sure for 1 letter. Maybe that's not possible, but you never know as there are so many top level domains.

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Cyberpunk Wannabe
*
Gender: Male
Posts: 43
280 credits
Members referred : 0


Lolo means Grandpa in the Philippines!


« Reply #6 on: May 07, 2007, 02:49:03 PM »

I know of 2 letter domains (eg. in.gr) but I am not sure for 1 letter. Maybe that's not possible, but you never know as there are so many top level domains.
100% Correct! This morning I thought they were all at least 2 letters.  But received a message today that i.tv is working and all single letter .tv domains are "available".  (There may be more tLds too!)

Anyway, nice function, I added it to my snippets file!  I also learned a lot more about $regexp!!!
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=426
Tags : php javascript email Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: Validate email adresses
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Jul 24, 2008, 05:08:28 PM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 35.717
Total Topics: 7.379
Total Members: 3.710
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: prolist

26 Guests, 4 Users online :

12 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.