Jump to content
Pardon our ads (a necessary update) ×

My input check is not catching...


joeneedshelp

Recommended Posts

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

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);

Archived

This topic is now archived and is closed to further replies.



×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.