1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
<?php
function is_valid_format_value ($val,$minLength,$maxLength,$regex=null,$required=true) {
$val = trimValue ($val);
if ($required AND emptyValue ($val))
return array('error' => 'required');
if(!is_null($regex) AND !preg_match ($regex,$val))
return array('error' => 'regex');
$length = pun_strlen($val);
if ($length<$minLength)
return array('error' => 'minLength', 'arg1' => $length, 'arg2' => $minLength);
if ($length>$maxLength)
return array('error' => 'maxLength', 'arg1' => $length, 'arg2' => $maxLength);
return array();
}
function is_valid_team_name ($val) {
$minLength = 3;
$maxLength = 30;
$regex = '/^[\w-. ]*$/';
return is_valid_format_value ($val,$minLength,$maxLength,$regex);
} |
Partager