Friday, 5 June 2015

PHP: Check number of characters in a range

<?php

//check the amount of characters in a string function

Function CheckNoChars($strText){
//check for between 6 and 12 characters
if (eregi("^.{6,12}$" , $strText))
return true;
else
return false;
}

?>

<?php

//test the function
$str1 = "mypasswordistoolong";
if (CheckNoChars($str1))

//if its OK display this message
echo "this has the correct number of characters";

//if its not OK display this one instead
else
echo "incorrect number of characters";

?>

0 comments:

Post a Comment