Click here to Skip to main content
15,995,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am trying to design a registration form and my whole form is working fine but only problem with email validation. here is my code for email validation. i got this validation code from internet.

html
XML
<tr>
      <th> <label for="user_email" ><span>*</span>User id(Email Address)</label></th>
      <td><input type="text" id="email" name="user_email"  class="inputText" /></td>
    </tr>



php

PHP
$user_email   											= clean( $_POST['user_email']);

$user_email = "someone@example.com"; 
if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $user_email)) { 
  echo "Valid email address."; 
} 
else { 
  echo "Invalid email address."; 
}
Posted
Updated 4-Apr-12 23:12pm
v2
Comments
Herman<T>.Instance 5-Apr-12 6:02am    
whihc php version do you use? the function is depricated since 5.3.0. See here: http://php.net/manual/en/function.eregi.php

1 solution

Your email validation absolutely fine, except that there is no function named clean in PHP. That is whu you might be getting an error. And why are you assigning an email id $user_email after you have already assigned post value to it. Instead use:

PHP
$user_email= $_POST['user_email'];
if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $user_email)) {
  echo "Valid email address.";
}
else {
  echo "Invalid email address.";
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900