You can try:
preg_match("/^.{6,24}$/u", $value);
^
and $
are anchors for start and end of the string.
the u modifier is used to read the string as an unicode string.
Frage
I'm trying to validate a password input of a user using php. Now I'm trying to require the user to put at least 6 chars. it doesn't matter if it's all letters or digits or any other language chars. In fact I want it to accept special chars from different languages... so I decided not to change the string expressing but limit the length of it I used this code
public function validpassword($value,$fields = NULL ,$reports = NULL){
global $reports;
if(preg_match($value, "/{6,24}/")){
return $value;
}else{
$reports[] = $fields.": 6-24 chars limit";
return false;
}
}
it doesn't really work. can you help me with that please. i've been looking over the web i can't seem to find something.
Lösung
You can try:
preg_match("/^.{6,24}$/u", $value);
^
and $
are anchors for start and end of the string.
the u modifier is used to read the string as an unicode string.
Andere Tipps
Try this
preg_match($value, "/^.{6,24}$/u");
You can also use strlen
Example:
if((strlen($value) < 6) || (strlen($value) > 24))
{
echo 'Min. length is 6 characters and max. length is 24 characters';
}