Could you please give any hints to implementing regex check?"> Password Regex Form with redirect - Forums

Forums

Password Regex Form with redirect

kus_kus 18 Sep, 2013
Hello!

I created a form which redirects to protected page upon entering any five digits in password field.

Here's the code at Custom Server Side Validation:

<?php
$data =& $form->data['password'];
$regex = '[0-9]{3}';
if ( isset($data) && $data ) {
  if ( preg_match($regex, $data) === 0 ) {
    $form->validation_errors['password'] = "Invalid data";
    return false;
  }
}
?>

Could you please give any hints to implementing regex check?
GreyHead 21 Sep, 2013
Hi kus_kus,

Basically that looks OK, I'd make some small changes to avoid a problem if $form->data['password'] isn't set and to add // to the regex:
<?php
if ( isset($form->data['password']) && $form->data['password'] ) {
  if ( preg_match('/[0-9]{3}/', $form->data['password']) === 0 ) {
    $form->validation_errors['password'] = "Invalid data";
    return false;
  }
}
?>
After that I'd add debug code to track exactly what is happening.

Bob
kus_kus 21 Sep, 2013
Great!

Thanks a lot for that!
This topic is locked and no more replies can be posted.