Northern Flame Posted January 1, 2008 Share Posted January 1, 2008 I've never used ereg() before, but am now trying it out. I want to only allow letters, numbers, and underscores in my usernames but the following script doesn't work: <?php $username = $_POST['username']; $ereg = ereg("([a-zA-Z0-9_])", $username); if ($ereg) { echo $username; } else { echo "Invalid format: $username"; } ?> if I am to input ';;;;;' it returns "Invalid format: ;;;;;" but if I enter 'test;' it returns 'test;' which means it accepted it, how can I fix this? Thanks for reading! Link to comment https://forums.phpfreaks.com/topic/83920-solved-ereg/ Share on other sites More sharing options...
Northern Flame Posted January 1, 2008 Author Share Posted January 1, 2008 never mind i found a fix: <?php $pattern = '([[:digit:]]|[~`!@#$%^&*(). =+{}|\:;"/?,]|[|]|-)+'; $name = stripslashes($_POST['username']); if (ereg($pattern, $_POST['username'])) { echo "error"; } else{ echo "ok"; } ?> Link to comment https://forums.phpfreaks.com/topic/83920-solved-ereg/#findComment-427095 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.