views:

125

answers:

2

I can't figure out where I'm going wrong here. Trying to validate an email address:

if (!preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/" , $emailREG)) {
+10  A: 

Try using FILTER_VALIDATE_EMAIL instead:

<?php
    $email = "someone@exa mple.com";

    if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
      echo "E-mail is not valid";
    }else{
      echo "E-mail is valid";
    }
?> 
cmptrgeekken
A: 

Be careful with filter_var with FILTER_VALIDATE_EMAIL. "somebody@example" will be validated as a valid email address because, well, it is a valid email address but may not be desirable.

You can also use the validate PEAR package.