cordoprod Posted April 28, 2008 Share Posted April 28, 2008 Hello! I develope a community system and I wonder which regex I should use. I only want the letters [a-z] and the numbers [0-9]. Not spaces and stuff like that.. Link to comment https://forums.phpfreaks.com/topic/103281-help-with-validating-username/ Share on other sites More sharing options...
pocobueno1388 Posted April 28, 2008 Share Posted April 28, 2008 <?php if (ereg("[^A-Za-z0-9]", $string)) { echo "Error: String can only contain letters and numbers!"; } ?> Link to comment https://forums.phpfreaks.com/topic/103281-help-with-validating-username/#findComment-528949 Share on other sites More sharing options...
woobarb Posted April 28, 2008 Share Posted April 28, 2008 'm assuming you wanting to match? $res = preg_match("/^[0-9a-z]$/", $s); you might want to make it case insensitive also... oh, hi pocobueno1388.... Link to comment https://forums.phpfreaks.com/topic/103281-help-with-validating-username/#findComment-528952 Share on other sites More sharing options...
cordoprod Posted April 28, 2008 Author Share Posted April 28, 2008 No, now it has to contain numbers, right? It shouldn't need numbers, but only numbers 0-9 and characters a-z is allowed. Link to comment https://forums.phpfreaks.com/topic/103281-help-with-validating-username/#findComment-528965 Share on other sites More sharing options...
cordoprod Posted April 28, 2008 Author Share Posted April 28, 2008 Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in /customers/cordoproduction.com/cordoproduction.com/httpd.www/travek/travek.php on line 28 I get that error... Here's my code: function IsUsername($username) { $regex = preg_match("/^[0-9a-z]$/", $s); if ( preg_match($regex, $username )) { return true; } else { return false; } } Link to comment https://forums.phpfreaks.com/topic/103281-help-with-validating-username/#findComment-528968 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.