How to validate Email in yii

Yii is a great framework for form validation,today i am going to show you how to validate the email field in the form before submitting.Its very simple just follow the below example

if you created a user model with email as one attribute
then in the rules function add the following code

public function rules()
 {
  
  return array(
   ...
   array('email', 'email','checkMX'=>true),
   ..
  );
 }

thats it

also look at the code i have added a checkMX=true(this is used for checking that domain exists),you could ignore it if you want

Comments

  1. thanks. i have spent over 2 hours on the internet looking for this information.

    Thank You

    ReplyDelete
  2. Thank you for the valuable info. It works great, although I'd love to know how the checkMX works ? Does it ping the domain, or...?

    ReplyDelete
  3. Thank you. you can save my time

    ReplyDelete
  4. the checkmx dosent work for me .. it dose not check the domaim .. pls help

    ReplyDelete
  5. How to override other unique domains like blabla.me ?

    ReplyDelete

Post a Comment

Popular posts from this blog

how to Add Piecemaker a Flash 3D image rotator to blogger