简体   繁体   English

cakephp - 电子邮件的验证规则是什么

[英]cakephp - what is the validation rule for email

I have a form in my cakephp app which requires an email address.我的 cakephp 应用程序中有一个表单,它需要一个电子邮件地址。 I'm using some custom javascript validation to make sure the email address is valid and I want to mimic however cakephp decides if an email address is valid so I know it'll save ok when the form actually submits.我正在使用一些自定义 javascript 验证来确保电子邮件地址有效,我想模仿但 cakephp 决定电子邮件地址是否有效,所以我知道它会在表单实际提交时保存。

So at the minute I'm only checking if there's an @ symbol.所以此刻我只检查是否有@ 符号。 What else does cakephp do to check an email address is valid? cakephp 还能做什么来检查电子邮件地址是否有效?

Please read the documentation http://book.cakephp.org/2.0/en/models/data-validation.html#Validation::email请阅读文档http://book.cakephp.org/2.0/en/models/data-validation.html#Validation::email

And take a look at the source code.并查看源代码。 All the answers are right there.所有的答案都在那里。

class User extends AppModel {
    public $validate = array(
        'email' => array(
            array(
                'rule' => array('email'),
                'message' => 'Please enter a valid email address',
            ),
        ),
    );
}

In your Model,put this在你的模型中,把这个

public $validate = array(
             //.... other validation here
        'email'=>array(
            'Valid email'=>array(
                'rule'=>array('email'),
                'message'=>'Please enter a valid email address'
            ),));

It'll automatically validate it when you submit (save)当您提交(保存)时它会自动验证它

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

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