1

I would like to check in PHP that if you enter something you need at least 30 characters.

If I run it now I can just keep going if I type nr: 31 for example.

if(empty($_POST['vraag'])) { 
    $vraagErr = 'Verplicht!'; 
} else { 
    $vraag = test_input($_POST['vraag']);

    if($_POST['vraag']<"30") { //This is the if instruction 
        $vraagErr = 'U moet meer dan 30 karakters invullen'; 
    }
}
Aksen P
  • 4,564
  • 3
  • 14
  • 27
  • Does this answer your question? [Limit String Length](https://stackoverflow.com/questions/3019285/limit-string-length) – Peca Mar 24 '20 at 10:09

2 Answers2

1

Use strlen() to check this length:

if(strlen($_POST['vraag'])<30) { ...

Note: I'm suggesting you to use trim() as well.

Aksen P
  • 4,564
  • 3
  • 14
  • 27
0

Use mb_strlen() to check it.

    if(mb_strlen($_POST['vraag']<"30")){

        // ....
    }
LF00
  • 27,015
  • 29
  • 156
  • 295