frijole Posted February 3, 2008 Share Posted February 3, 2008 I would like to check a string to see if the username has any illegal characters, i.e. anything that is not a letter or a number, Any ideas? Link to comment https://forums.phpfreaks.com/topic/89144-solved-how-can-i-check-for-illegal-characters-in-a-string/ Share on other sites More sharing options...
p2grace Posted February 3, 2008 Share Posted February 3, 2008 This should do the trick: <?php $text = "test123"; if (!ereg('[^A-Za-z0-9]', $text)) { echo "contains only letters and numbers"; }else{ echo "contains invalid characters."; } ?> Link to comment https://forums.phpfreaks.com/topic/89144-solved-how-can-i-check-for-illegal-characters-in-a-string/#findComment-456530 Share on other sites More sharing options...
frijole Posted February 5, 2008 Author Share Posted February 5, 2008 the ereg() function returns the length of string? I read the manual and i do not understand how the !ereg() argument works? can anyone clarify this for me? Link to comment https://forums.phpfreaks.com/topic/89144-solved-how-can-i-check-for-illegal-characters-in-a-string/#findComment-459012 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.