Get the App
SLTechnology News&Howtos  ›  Development  › 

How php implements Extensible validation classes

Shulou Source: shulou.com Published: 2022-06-03 19:31:57 09月30日 Update

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!

Tags: Rules parameters data validation results methods articles content references tests not much usage names multiple most mobile phones numbers files methods more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Redmi OPPO Reno NVidia Xiaomi