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!

Link to comment
Share on other sites

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;
  }
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.