Jump to content

[SOLVED] email validation through preg_match! registration form!


samoi

Recommended Posts

Hello Guys!

 

Look through this code:

<?php

/**
* @author samoi
* @copyright 2009
*/
error_reporting(E_ALL & E_NOTICE);
include ('func.php');

if (!isset($_POST['submit'])) {


    echo '<form action="" method="post">
  username: <input type="text" name="username" />
  <br />
  password: <input type="password" name="password" />
  <br />
  email:
  <br />
  <input type="text" name="email" />
<input type="submit" name="submit" value="register" />
  </form>';


} else {


    if (!empty($_POST['username'])) {
        if (!empty($_POST['password'])) {
            if (!empty($_POST['email'])) {
            	$email = $_POST['email'];
                if (!preg_match('/([\w-\.]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4})\be(\w*)s\b/', $email)) {
					echo 'Enter a valid email format!';
					exit;
                    
                } else {
                	
                    $user = $_POST['username'];
                    $pass = md5($_POST['password']);
                    
                    if (checkreg($user, $email)) {
                        register($user, $pass, $email);
                        echo 'Welcome ' . $user .
                            ' You have been sent an email regarding your registration!';
                    } else {
                        echo 'There is a user or email with that user or email you entered!';
                    }
                }


            } else {
                echo 'Email is not entered!';
                exit;
            }
        } else {
            echo 'Password is not entered!';
            exit;
        }
    } else {
        echo 'User is not entered!';
        exit;
    }
}
?>

 

problem: Everything goes great except for the email validation !

 

It keeps giving me that the email is wrong format!

 

Help me please!

you might try the following function:

 

function valid_email($address) {
  // check an email address is possibly valid
  if (ereg("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $address)) {
    return true;
  } else {
    return false;
  }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.