14, February 2012

Validate email adresses - webmaster forum

 
Webdigity webmaster forums
[ 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
Instabuck - The easy way to sell digital products online

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



« on: Sep 21, 2005, 03: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 or twitter

Last blog : Butterfly Marketing 2.0
Novice Spammer
***
Posts: 100
103 credits
Members referred : 0



« Reply #1 on: Sep 27, 2005, 10: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: 1525
6359 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #2 on: Oct 03, 2005, 05: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 : Canonical URL Links / Tags
I wish I was an Oscar winner
**
Posts: 86
247 credits
Members referred : 0



« Reply #3 on: Oct 03, 2005, 05: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, 10: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 (2 letters in the 2nd level).
and
www.JP.TO (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: 5779
46271 credits
Members referred : 3



« Reply #5 on: May 07, 2007, 12: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 or twitter

Last blog : Butterfly Marketing 2.0
Cyberpunk Wannabe
*
Gender: Male
Posts: 43
280 credits
Members referred : 0


Lolo means Grandpa in the Philippines!


« Reply #6 on: May 07, 2007, 01: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....

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?
Feb 14, 2012, 08:22:32 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!






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