How to validate email using Yii Model validation rules function code. Also how to check email exist or not using Model validation rules function in Yii.
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Follow the few modifications as below: Follow your file as per your module you have used.
Thank you
You can create your custom validation method to fulfill your requirement.
Create a function in model class:
User this validation method in rules:
You can easily find either email is already present in your db or not by defining the rule.
Here is the rule.
Example.
Here i want to put validation on Email, which is unique, my model class name is User, attributeName is the field name of the table i.e. email and if email is already present in your table then display message.
If it gives error then you may change your table and make unique the email field.
ALTER TABLE user ADD UNIQUE (email)
Then check.
other email validations are in below. which i think complete set of email validation.
That's it. Thanks
You can set your model validations as below
Yii Reference Link For More Detail: http://www.yiiframework.com/wiki/56/
For Yii2 I used the following in a model called Register which will use the User Class.
You need to use targetClass and put the Namepsace for the Class User
Custom validation, short and sweet code. try this it's working fine -
write this custom function in the same model -