Last active
November 19, 2020 11:07
-
-
Save alex-authlab/5160a4c564d3a24067e523f3b6490429 to your computer and use it in GitHub Desktop.
Fluent Form Password Strogn Requirement
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter('fluentform_validate_input_item_input_password', function($errorMessage, $field, $formData, $fields, $form){ | |
$target_form_id = 9; | |
if($form->id != $target_form_id){ | |
return; | |
} | |
$password = $formData['password']; | |
$errorMessage = ''; | |
//numbers | |
$pattern = "/[0-9]/"; | |
$match = preg_match($pattern,$password); | |
if (!$match){ | |
$errorMessage= "You need atleast 1 number!"; | |
return [$errorMessage]; | |
} | |
// 8 charcter min | |
$pattern = "/(?=.{8,})/"; | |
$match = preg_match($pattern,$password); | |
//preg_match($pattern, $password, $matches, PREG_OFFSET_CAPTURE, 0); | |
if (!$match){ | |
$errorMessage= "You need minimum 8 charcter!"; | |
return [$errorMessage]; | |
} | |
// small and capital | |
$pattern = "/(?=.*[a-z])(?=.*[A-Z])/"; | |
$match = preg_match($pattern,$password); | |
if (!$match){ | |
$errorMessage= "You need one to 1 smaller and 1 upper charcter!"; | |
return [$errorMessage]; | |
} | |
// special charcter | |
$pattern = "/(?=.*[^\w\d])/"; | |
$match = preg_match($pattern,$password); | |
if (!$match){ | |
$errorMessage= "You need one to 1 special charcter !"; | |
return [$errorMessage]; | |
} | |
return ; | |
},10,5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment