Jump to content

eregi help


fantomel

Recommended Posts

i`m back i have made the changes in the code where i needed but i need some experts who used before preg_match since it's my first time.. and i would to know if it's correct.

 

<?php

if (isset($_POST['submit'])) {
    if (empty($_POST['username'])) {
        $errors[] = 'Empty Username.';
    }
    if (strlen($_POST['username']) < 4) {
        $errors[] = 'Username too short.';
    }
    if (strlen($_POST['username']) > 10) {
        $errors[] = 'Username too long.';
    }
    if (!preg_match('^[a-zA-Z0-9]*$', $_POST['username'])) {
        $errors[] = 'Username Contains Invalid Characters.';
    }

    if (empty($_POST['password'])) {
        $errors[] = 'Empty Password';
    }
    if (strlen($_POST['password']) < 6) {
        $errors[] = 'Password too short';
    }
    if (!preg_match('^[a-zA-Z0-9]*$', $_POST['username'])) {
        $errors[] = 'Password Contains Invalid Characters.';
    }
    if (empty($_POST['name']) || !preg_match('^[a-zA-Z0-9]*$', $_POST['name'])) {
        $errors[] = 'Name is empty or incorect.';
    }
    if (empty($_POST['surname']) || !preg_match('^[a-zA-Z0-9]*$', $_POST['surname'])) {
        $errors[] = 'Surname is empty or incorect.';
    }
    if (empty($_POST['address']) || !preg_match('^[a-zA-Z0-9]*$', $_POST['address'])) {
        $errors[] = 'Adress is empty or incorect.';
    }
    if (empty($_POST['email']) || !preg_match('^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,4}$',
        $_POST['email'])) {
        $errors[] = 'E-mail is empty or incorect.';
    }
    if (empty($_POST['zipcode']) || !preg_match('^[0-9]*$', $_POST['zipcode'])) {
        $errors[] = 'Zip Code is empty or incorect.';
    }
    if (empty($_POST['phone']) || !preg_match('^[0-9]*$', $_POST['phone'])) {
        $errors[] = 'Phone is empty or incorect.';
    }
$username = $_POST['username'];
$sql = "SELECT * FROM `tbl_users` WHERE `username_users` = '$username' ";
$result = mysql_query($sql);
if(mysql_num_rows($result) > 0)
{
	$errors[] = 'Username Exists.';
}
if(count($errors) < 1)
	echo "Processing...";

}
?>
<form id="loginform" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
    <fieldset>
        <legend>
            Register
        </legend>
        <p>
	<?php 
if (isset($errors)) {
    if (count($errors)) {
        $error_string = implode('</li><li>', $errors);
        echo $error_string = "
        <div class='form_errors'>
          The following errors were encountered while processing your request:
          <ul><li>{$error_string}</li></ul>
        </div>";
    }
} ?>
        </p>
        <label for="username">
            <input name="username" tabindex="1" id="username" type="text" value="">Username: 
        </label>
        <label for="password">
            <input name="password" tabindex="2" id="password" type="password" value="">Password:
        </label>
        <label for="Name">
            <input name="name" tabindex="3" id="name" type="text" value="">Name:
        </label>
        <label for="Surname">
            <input name="surname" tabindex="4" id="surname" type="text" value="">Surname: 
        </label>
        <label for="address">
            <input name="address" tabindex="5" id="address" type="text" value="">Address: 
        </label>
        <label for="email">
            <input name="email" tabindex="6" id="email" type="text" value="">Email: 
        </label>
        <label for="phone">
            <input name="phone" tabindex="7" id="phone" type="text" value="">Phone: 
        </label>
        <label for="zipcode">
            <input name="zipcode" tabindex="8" id="zipcode" type="text" value="">Zip Code: 
        </label>
        <label for="city">
            <input name="city" tabindex="9" id="city" type="text" value="">City: 
        </label>
        <label for="submit">
            <input name="submit" id="submit" tabindex="4" value="Log in" type="submit">
        </label>
    </fieldset>
</form>

Link to comment
https://forums.phpfreaks.com/topic/170288-eregi-help/#findComment-898782
Share on other sites

You need to start your regex patterns with delimiters first, eg ~your pattern here~

 

So the following pattern ^[a-zA-Z0-9]*$ can be rewritten as ~([A-Z0-9]+)~i

 

I would recommend you to have read of this regex tutorial for the basics on regular expressions. Also check out regular-expressions.info too.

 

 

Link to comment
https://forums.phpfreaks.com/topic/170288-eregi-help/#findComment-898785
Share on other sites

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.