JSHINER Posted July 15, 2008 Share Posted July 15, 2008 I have this to check for invalid chars: <?php if (!preg_match('/^[a-zA-Z]$/',$data) { echo "FAIL - invalid username"; } ?> But how do I also get it to check for spaces. Link to comment https://forums.phpfreaks.com/topic/114832-solved-validating-a-field-no-invalid-chars-or-spaces/ Share on other sites More sharing options...
rhodesa Posted July 15, 2008 Share Posted July 15, 2008 are you saying you want to allow spaces in your usernames? currently, this check will only allow lower case and upper case letters. to allow spaces too it would be: <?php if (!preg_match('/^[a-zA-Z ]$/',$data) { echo "FAIL - invalid username"; } ?> Link to comment https://forums.phpfreaks.com/topic/114832-solved-validating-a-field-no-invalid-chars-or-spaces/#findComment-590469 Share on other sites More sharing options...
JSHINER Posted July 15, 2008 Author Share Posted July 15, 2008 I only want to allow upper/lowercase letters and numbers - no special characters or spaces allowed. Link to comment https://forums.phpfreaks.com/topic/114832-solved-validating-a-field-no-invalid-chars-or-spaces/#findComment-590471 Share on other sites More sharing options...
samshel Posted July 15, 2008 Share Posted July 15, 2008 this will give small case, upper case letters and numbers only <?php if (!preg_match('/^[a-zA-Z0-9]+$/',$data) { echo "FAIL - invalid username"; } ?> PS: added a + at the end to allow more than one charachters. i think you need that ? Link to comment https://forums.phpfreaks.com/topic/114832-solved-validating-a-field-no-invalid-chars-or-spaces/#findComment-590474 Share on other sites More sharing options...
rhodesa Posted July 15, 2008 Share Posted July 15, 2008 this will give small case, upper case letters and numbers only <?php if (!preg_match('/^[a-zA-Z0-9]+$/',$data) { echo "FAIL - invalid username"; } ?> PS: added a + at the end to allow more than one charachters. i think you need that ? what they said....and you'll definitely need the plus... Link to comment https://forums.phpfreaks.com/topic/114832-solved-validating-a-field-no-invalid-chars-or-spaces/#findComment-590476 Share on other sites More sharing options...
JSHINER Posted July 15, 2008 Author Share Posted July 15, 2008 Works great. Thanks! Yes, generally more than one character helps in usernames Link to comment https://forums.phpfreaks.com/topic/114832-solved-validating-a-field-no-invalid-chars-or-spaces/#findComment-590601 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.