aenigma Posted July 20, 2008 Share Posted July 20, 2008 Hey, I was wondering if there was a way to make sure a string from an input box doesn't contain anything except a-z and 1-0 without checking an entire string against every character I don't want. Thanks for any help! Link to comment https://forums.phpfreaks.com/topic/115689-form-text-input-check-string-for-characters/ Share on other sites More sharing options...
mga_ka_php Posted July 20, 2008 Share Posted July 20, 2008 use regex Link to comment https://forums.phpfreaks.com/topic/115689-form-text-input-check-string-for-characters/#findComment-594816 Share on other sites More sharing options...
aenigma Posted July 20, 2008 Author Share Posted July 20, 2008 Well, although that was REALLY vague, lol, I managed to read enough to figure it out. Here's what I came up with: if (!ereg("^[a-zA-Z0-9_]{4,16}$", $_POST["uname"])) { echo "Invalid Username<br>Usernames must be between 4 and 16 characters, contain only alphanumeric characters and \"_\""; $allchecks = 0; } Link to comment https://forums.phpfreaks.com/topic/115689-form-text-input-check-string-for-characters/#findComment-595009 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.