简体   繁体   English

验证Magento表单输入

[英]Validate Magento form input

My validation code outputs a error message only if something is written into the field. 仅当在字段中写入内容时,我的验证代码才会输出错误消息。 How can I also return the error message when the input field is left empty? 当输入字段保留为空时,如何返回错误消息?

['validate-firstname', 'Please enter your firstname', function (v) {
            return Validation.get('IsEmpty').test(v) ||  /^[a-zA-Z]+$/.test(v)
        }],

If it's an input field then you would just add the class required-entry to it. 如果这是一个输入字段,那么您只需向其添加required-entry类。

As you can see in js/prototype/validation.js where the validation is declared (it's all based on Andrew Tetlaw's work here -> https://github.com/atetlaw/Really-Easy-Field-Validation ) 如您在js/prototype/validation.js中看到的声明了验证的声明(全部基于Andrew Tetlaw在这里的工作-> https://github.com/atetlaw/Really-Easy-Field-Validation

['required-firstname', 'Please enter your first name.', function(v) {
            return !Validation.get('IsEmpty').test(v);
        }], 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM