You haven't anchored your regex to the beginning of the input, so it will accept any string that contains [a-zA-Z]. Unfortunately, the solution uses the ^ character, which will break the FormIt tag. This regex would handle both the first character requirement and the min length:
but the FormIt will interpret the ^ character as a delimiter for the property rather than part of the regex.
I don't see any way out except for a custom validator (untested):
&validate=`password:checkPassword`
/* checkPassword snippet */
$success = true;
$value = trim($value);
if (strlen($value) < 6) {
$success = false;
$validator->addError($key, 'Must be at least 6 characters long!');
}
if (!preg_match('/^[a-z]/i', $value)) {
$success = false;
$validator->addError($key, 'Must start with a letter!');
}
return $success;
The good news it that as long as you're doing a custom validator, you could also test password strength.
[ed. note: BobRay last edited this post 11 years, 6 months ago.]