Matching a string between 4 and 128 characters with PHP and Regex.

Works with preg_match and preg_match_all which use the PCRE Library.

 

$string = "tutorial";

if (!preg_match('#^(.){4,128}$#', $string)) {

 echo 'The string you entered is invalid.';

}

Categorized in:

Tagged in:

, , , ,