简体   繁体   中英

How to validate both greater than AND less than

I am writing validation for a book management system, and I want to make it so that if the length of the ISBN entered is either less than or greater than 13 or 10, it displays the error message, however it says that there is an unexpected '<' whenever I try the following.

  if(strlen($_POST['isbndelete'] (< 13 || 10) || (> 13 || 10)))
  {
    $error="The length of the ISBN is incorrect.";
    echo $error;
    return false;
  }

All help is appreciated!

Your main issue is that your condition is not valid PHP. You should read more about conditional statements syntax.


Validing ISBN length

ISBNs are either 10 or 13 characters.

So you can simply check if your string does not contain exactly 10 and does not contain 13 characters either , like this:

$len = strlen($_POST['isbndelete']);
if ($len != 10 && $len != 13) {
  $error = "The length of the ISBN is incorrect.";
  echo $error;
  return false;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM