1

I have a model which contains emails with some other fields. I want a custom filter in Yii CGridView's advance search which when applied, lists only Invalid Email IDs (using regular expression '^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$')

Note: I dont want to add any column in CGridView

rtruszk
  • 3,902
  • 13
  • 36
  • 53
Mohammad Qasim
  • 186
  • 3
  • 16
  • That's not the regex for valid email adresses; that would look more like `(?:[a-z0-9!#$%&'*+/=?^_\`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_}\`{|}~-]+)*|”(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*”)@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])`; but actually is way [more complicated](http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html). – Marcus Müller Feb 06 '15 at 11:07
  • Thanks for your correction, But can you please tell me the answer of my real problem – Mohammad Qasim Feb 06 '15 at 11:12
  • Sorry, I'm no Yii expert, just wanted to point out that email addresses usually are not uppercase alphanumerical...; I would have written an answer if I had one. However, your question is not really well-written. Maybe add what you've already tried, why the official documentation has failed you, etc. – Marcus Müller Feb 06 '15 at 11:14

1 Answers1

0

I hope to help you out,

you will need several things

  1. the line for filtering in the column of your choice...(i recommend you create a new attribute for this, ask me in comments if you want to know more why.) this goes in the cgridview of course:

    'filter'=>CHtml::activeCheckBox($model, $attributeEmail)

  2. the condition in your search of function that brings up the model.

Supposing you have a criteria inside your search in your model wich help you with your filtering what you need is ...

if($this->EMAIL == TRUE)
{
    $criteria->addCondition("\"t\".\"EMAIL\" email NOT LIKE '%_@__%.__%'");
}

Why not to use regex and make a KISS approach ? better read this first...

Sql script to find invalid email addresses

I'd be glad to hear your comments it is interesting question for yii dev's btw

Community
  • 1
  • 1
DiegoCoderPlus
  • 760
  • 6
  • 14