ammar77 Posted July 21, 2008 Share Posted July 21, 2008 Hi guys, This little code accept only alphabets and numbers but i want to customize it to accept "-" "_" and "." values, kindly help me in this regard..thanks code =============== <? include("config.php"); if (strstr($_SERVER['HTTP_REFERER'], $root)); else { header ("Location: $rooturl"); } $ip = $_SERVER['REMOTE_ADDR']; $url = mysql_real_escape_string($_POST['url']); if(preg_match('|^http(s)?://[a-z0-9-]+(\.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url)) { if (empty($_POST['tag'])) { $query = mysql_query("INSERT INTO $table (ip,url) VALUES ('$ip','$url')") or die('MySQL error: '.mysql_error()); $qs = mysql_insert_id(); } else { if (ereg('^[a-zA-Z0-9]+[a-zA-Z0-9]+$', $_POST['tag'])) { $tag = mysql_real_escape_string($_POST['tag']); $query = mysql_query("select * from $table where `tag` = '$tag';") or die('MySQL error: '.mysql_error()); if (mysql_num_rows($query) != 0) die("This tag has already been taken! Please press the back button on your browser and choose another tag!"); else { $query = mysql_query("insert $table (ip,url,tag) VALUES ('$ip','$url','$tag')") or die('MySQL error: '.mysql_error()); $qs = $tag; } } else die('Your tag consists of invalid characters! Only alphabets and numbers allowed! Please press the back button on your browser and choose another tag!'); } $link = $destination . $qs; require 'create_template.php'; } else echo 'Your URL is invalid'; ?> =========================== Quote Link to comment Share on other sites More sharing options...
effigy Posted July 22, 2008 Share Posted July 22, 2008 Use [-\w\.] with PREG and the /i modifier. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.