php - number that start with 2 digits in form validation -


i tried substract 'pick up' 2 digits not work ,'boleta' have start '20',else show message "introduce solo los 10 digitos de tu boleta!".

thanks!

<?php // define variables , set empty values $nombreerr = $boletaerr = ""; $nombre = $boleta =  "";  if ($_server["request_method"] == "post"){ if (empty($_post["boleta"])){ $boletaerr = "boleta required"; } else{ $boleta = test_input($_post["boleta"]); $boletavalida=substr($boleta,0,2);  //check if boleta contains numbers if (!preg_match('/^[0-9]{10}+$/', $boleta) && !$boletavalida ==20){ $boletaerr="introduce solo los 10 digitos de tu boleta!"; }    } }  function test_input($data){ $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> 

this following line incorrect:

if (!preg_match('/^[0-9]{10}+$/', $boleta) && !$boletavalida == 20) { 

you negating value of $boletavalida when instead, mean "is not equal to" should using != operator.

try below:

if (!preg_match('/^[0-9]{10}+$/', $boleta) && $boletavalida != '20') { 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -