I have a form in my cakephp app which requires an email address. 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.
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?
I have a form in my cakephp app which requires an email address. 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.
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?
Share Improve this question asked Feb 10, 2014 at 23:50 crazy sarahcrazy sarah 6314 gold badges13 silver badges29 bronze badges3 Answers
Reset to default 2Please read the documentation http://book.cakephp/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)