Jump to content

[SOLVED] client side regular expression checking that text is not ^.+@.+\\..+$


Rother2005

Recommended Posts

client side regular expression I’ve found that you need to use the

if (!ereg(^.+@.+\\..+$

code but I just don’t know how to implement it in the code

can anyone help??

[code]<?php
include('connect1.inc');?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Booze Cruise Reg</title>

</head>
<body>

<?php
if(!$_POST['register']){echo'<p align="center"><strong>Member Registration</strong></p>
<form name="form1" method="POST" action="">
<p align="center">Username:  <input type="text" name="username" maxlength="10"></p>
<p align="center">Password:  <input type="password" name="password" maxlength="10"></p>
<p align="center">Firsname:  <input type="text" name="firstname" maxlength="20"></p>
<p align="center">Surname:  <input type="text" name="surname" maxlength="20"></p>
<p align="center">Address 1: <input type="text" name="address1" maxlength="20"></p>
<p align="center">Address 2: <input type="text" name="address2" maxlength="20"></p>
<p align="center">Town:      <input type="text" name="town" maxlength="20"></p>
<p align="center">County:    <input type="text" name="county" maxlength="20"></p>
<p align="center">Postcode:  <input type="text" name="postcode" maxlength="7"></p>
<p align="center">Tel No:    <input type="text" name="telno" maxlength="12"></p>
<p align="center">Mobile:    <input type="text" name="mobile" maxlength="12"></p>
<p align="center">Email:    <input type="text" name="email" maxlength="30"></p>
<p align="center"><input type="submit" name="register" value="Enter Details"></p></form>';}
//27
else{
//checks if user has input text

if(isset($_POST['username']) && !empty($_POST['username']))
{
    // valid
$username = $_POST['username'];
}
else
{
    // not valid
die ("No Username Input");
}

if(isset($_POST['password']) && !empty($_POST['password']))
{
    // valid
$password = $_POST['password'];
}
else
{
    // not valid
die ("No Password Input");
}

if(isset($_POST['firstname']) && !empty($_POST['firstname']))
{
    // valid
$firstname = $_POST['firstname'];
}
else
{
    // not valid
die ("No Firstname Input");
}


if(isset($_POST['surname']) && !empty($_POST['surname']))
{
    // valid
$surname = $_POST['surname'];
}
else
{
    // not valid
die ("No Surname Input");
}

if(isset($_POST['address1']) && !empty($_POST['address1']))
{
    // valid
  $address1 = $_POST['address1'];
}
else
{
    // not valid
die ("No Address Input");
}

if(isset($_POST['town']) && !empty($_POST['town']))
{
    // valid
  $town = $_POST['town'];
}
else
{
    // not valid
die ("No Town Input");
}

if(isset($_POST['county']) && !empty($_POST['county']))
{
    // valid
  $county = $_POST['county'];
}
else
{
    // not valid
die ("No County Input");
}

if(isset($_POST['postcode']) && !empty($_POST['postcode']))
{
    // valid
  $postcode = $_POST['postcode'];
}
else
{
    // not valid
die ("No Postcode Input");
}

if(isset($_POST['email']) && !empty($_POST['email']))
{
    // valid
  $email = $_POST['email'];
}
else
{
    // not valid
die ("No Email Input");
}

//encrypts password server side into md5 32bytes
$password = stripslashes($password);
$password = md5($password);

$sql = "INSERT INTO member(Username,Password,Firstname,Surname,Address1,Address2,Town,County,Postcode,TelNo,Mobile,Email)
VALUES ('$username','$password','$firstname','$surname','$address1','$address2','$town','$county','$postcode','$telno','$mobile','$email')";

mysql_query($sql)             

or die(mysql_error());
//50
echo ("<meta http-equiv=\"Refresh\" content=\"2; URL=members.php\"/>Thank You! You will be redirected");}
?>
</body>
</html>[/code]

are you trying to make sure an email is valid? if so this is what i use on my form that might help:

[code]    if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email_address)) {
        echo "The email you entered is not valid. Please try again. <br/>";
exit();
    }[/code]

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.