Monday, April 27, 2015

Validate Email using Validator of Cakephp3

Let's assume you need to validate an email that is not a part of model Entity. If it was a field in model, the validation rules in model would have taken care of it. But in this case, you need to validate the email address yourself. So, what will you use? A regex ? No, instead you can use the Validation class of Cake.

So, How do we validate an email in cakephp3 using it's validator?

It's simple :

First insert the below line in your controller or Model :

use Cake\Validation\Validation;

This will include the validation class in your file.

Now use the below line in your function :

$check=Validation::email('email to be validated');

If $check is true, then it's a valid email else the email is invalid.




9 comments:

  1. it's such a nice information for validation about cakephp.it's a most valuable information for cakephp users. more information about cakephp click here school signs uk

    ReplyDelete
  2. Nice Article, Thanks for writing such informative post.
    If your looking for cakephp interview questions please refer to
    Cakephp Interview Questions

    ReplyDelete
  3. Actually i want to verify email address that's why i was looking a great website where i can get information about it. I think this website is very helpful for me because here already i got more information about it. I hope next time i will get another valuable information here. Thanks for your great post.

    ReplyDelete
  4. Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place.. http://verifications.io

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Thanks for sharing such a nice information with us on PHP and related topics. Very useful lines and to the point. I appreciate your effort , keep sharing such wonderfull things.

    https://www.interviewsortout.com/in-how-many-ways-we-can-use-model-in-cakephp/

    ReplyDelete