Jump to content

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.