0

I have a $name variable containing a string, and when I test it, I never get the "Name should be between 2 and 40 characters" error even when it's less than 2 characters long or more than 40. Why?

if (strlen($name) < 2 && strlen($name) > 40) {
    $nameError = 'Name should be between 2 and 40 characters';
}
1
  • @T.J.Crowder I think this one will be used for later questions ;-) Commented Feb 12, 2017 at 16:41

1 Answer 1

6

How can the length be less than 2 and greater than 40? You want || ("or"), not && ("and").

if (strlen($name) < 2 || strlen($name) > 40) {
// -------------------^^
Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.