Custom meaningful error message for Zend RegEx Validator

天大地大妈咪最大 提交于 2019-12-04 05:33:12

How about telling the user in layman's terms what your restrictions are? Like

Error: Only the letters A to Z and numbers are allowed.

(Which leads me to the question why first names can contain numbers...)

For your custom error message(s) in zend standart validators just pass the messages array to the validator while instantiating. It's an array, which keys are error types (see further), and values - error messages.

->addValidator('regex', true, 
                       array(
                           'pattern'=>'/^[(a-zA-Z0-9)]+$/', 
                           'messages'=>array(
                               'regexNotMatch'=>'Your own custom error message'
                           )
                       )
)

To see error keys for other error types of chosen validator you may refer to it's source code. For regex validator it's located at {Zend Framework Library}/Zend/Validate/Regex.php .

Good luck in validating :).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!