joeneedshelp Posted November 27, 2011 Share Posted November 27, 2011 I did not post this in Regex because I do not believe it is a problem with the preg_match. My input check on the username length works without any problems, however the check to make sure the user only uses a-z and whitespace does not work. I am not sure why and I am new to PHP. Should I setup the input check differently? The error code is never displayed if I input "!@*(#(!$)$@(" and it will not stop that from being submitted. Any help is GREATLY appreciated!! if(strlen(trim($_POST['name'])) > 15 || strlen(trim($_POST['name'])) < 1) { $errors[] = $lang['No name']; } if(preg_match('/[^a-z]\s/i', $_POST['name'])) { $errors[] = $lang['Invalid char']; } Link to comment https://forums.phpfreaks.com/topic/251898-my-input-check-is-not-catching/ Share on other sites More sharing options...
Pikachu2000 Posted November 27, 2011 Share Posted November 27, 2011 You don't really need to use a regex pattern for this at all. $errors = array(); $name = trim($_POST['name']); if( !empty($name) ) { if( strlen($name) > 15 ) { $errors[] = 'Name must be 15 characters or less.'; } if( !ctype_alpha(str_replace(' ', '', $name)) ) { $errors[] = 'Name may contain only letters and spaces.'; } } else { $errors[] = 'Name may not be empty.'; } // print_r($errors); Link to comment https://forums.phpfreaks.com/topic/251898-my-input-check-is-not-catching/#findComment-1291610 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.