fantomel Posted August 14, 2009 Share Posted August 14, 2009 hello since php 5.3 eregi is deprecated can you please advice me what function should i use instead and give an example ? thank you very much Link to comment https://forums.phpfreaks.com/topic/170288-eregi-help/ Share on other sites More sharing options...
wildteen88 Posted August 14, 2009 Share Posted August 14, 2009 Use preg_match. Do note that preg_* based functions require you to use regex. Link to comment https://forums.phpfreaks.com/topic/170288-eregi-help/#findComment-898277 Share on other sites More sharing options...
fantomel Posted August 14, 2009 Author Share Posted August 14, 2009 ok i understand Link to comment https://forums.phpfreaks.com/topic/170288-eregi-help/#findComment-898278 Share on other sites More sharing options...
.josh Posted August 14, 2009 Share Posted August 14, 2009 also note that the preg_x functions uses the pcre engine (perl compatible regular expressions) instead of the posix engine used by ereg_x functions, so there are some syntax and behavioral differences. Link to comment https://forums.phpfreaks.com/topic/170288-eregi-help/#findComment-898305 Share on other sites More sharing options...
fantomel Posted August 15, 2009 Author Share Posted August 15, 2009 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 More sharing options...
wildteen88 Posted August 15, 2009 Share Posted August 15, 2009 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 More sharing options...
DarkendSoul Posted August 15, 2009 Share Posted August 15, 2009 Side note. My last name contains a -, you should allow them them in your sir names. Link to comment https://forums.phpfreaks.com/topic/170288-eregi-help/#findComment-898796 Share on other sites More sharing options...
fantomel Posted August 15, 2009 Author Share Posted August 15, 2009 ok thank you very much i will have a look on both tutorials. Link to comment https://forums.phpfreaks.com/topic/170288-eregi-help/#findComment-898800 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.