⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

How to use setRule / setRules in password validation Enterprise Edition



larasmith
  • profile picture
  • Member

Posted 05 June 2017 - 01:34 AM

Regarding the confirm password. I cannot determine how to use password validation.
In the community edition I do password validation by:
 
$crud->set_rules('u_Pwd', 'Password', 'min_length[3]|max_length[20]');
$crud->set_rules('u_Cpass', 'Password Confirmation', 'matches[u_Pwd]|md5');
 
I tried doing it in the enterprise edition and generated an error upon save.
I also tried checking the valitron website and still cannot figure it out. Please help me understand on how to do it.
Please refer to the attached photo:
image.png

 

                


larasmith
  • profile picture
  • Member

Posted 07 June 2017 - 03:48 AM

I finally figure it out using the links:

1. Valitron: https://github.com/vlucas/valitron

2. API & Function: https://www.grocerycrud.com/enterprise/api-and-function-list/setRules

 

In my case I used a custom regex to achieve what I want:

 
$crud->setRules(
   [
       [
           'fieldName' => 'u_Pwd',
           'rule' => 'regex',
           'parameters'=> '/^[a-z\d\-_\s]+$/i'
           // Allow A-Z, 0-9, dash, underscore and space
       ],
       [
           'fieldName' => 'u_Pwd',
           'rule' => 'lengthMin',
           'parameters'=> '3'
       ],
       [
           'fieldName' => 'u_Cpass',
           'rule' => 'equals',
           'parameters'=> 'u_Pwd'
       ],
   ]
);

 

I just hope it helps someone too. Cheers!  :)


web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 13 June 2017 - 03:19 AM

I am glad that you could figure out the solution from the documentation :)

 

Thanks for sharing that knowledge