How php implements Extensible validation classes
Editor to share with you how php to achieve extensible verification class, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
The specific analysis is as follows:
Here is an extensible php validation class
The various types of verification that can be implemented in the class can be adjusted and implemented on their own, and now it is the basic implementation.
If you need to add a rule, define the method directly, and the method name is the rule name. Refer to the method of use.
Require_once ('. / Validator.class.php'); $data = array ('nickname' = >' heno', 'realname' = >' steven', 'age' = > 25,' mobile' = > '1521060426'); $validator = new Validator ($data); $validator- > setRule ('nickname',' required'); $validator- > setRule ('realname', array (' length' = > array (1pia 6), 'required'); $validator- > setRule (' age', array (required', 'digit')) $validator- > setRule ('mobile', array (' mobile')); $result = $validator- > validate (); var_dump ($result); var_dump ($validator- > getResultInfo ())
The Validator.class.php file is as follows:
These are all the contents of the article "how php implements Extensible validation classes". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!