Now I assume you are taking input as comma separated multiple emails. If
yes
use code like.

In Model

"email" => array(
'mustNotEmpty'=>array(
    'rule' => 'notEmpty',
    'message'=> 'Please enter to email(s)',
    'last'=>true),
'mustBeEmail'=> array(
    'rule' => 'validateEmails',
    'message'=> '',
    'last' => true)),

and put following function in same model

public function validateEmails($check) {
    $emails = array_values($check);
    $key = array_keys($check);
    $emails = explode(',', $emails[0]);
    foreach($emails as $email) {
        $email = trim($email);
        if(!empty($email)) {
            $valid = Validation::email($email);
            if(!$valid) {
                $this->validationErrors[$key[0]][0]= 'You have an error
near '.$email;
                break;
            }
        }
    }
    return true;
}


nothing to do in controller. only call validation method from controller.

good luck

On Fri, Nov 2, 2012 at 8:05 PM, Chris <[email protected]> wrote:

> thank you for your reply chetan,...
> I'm steel getting an error:
> Warning (2): preg_match() [function.preg-match]: Delimiter must not be
> alphanumeric or backslash [APP/controllers/invitations_controller.php, line
> 83]
>
> this is my invitations model:
>
>     var $validate = array(
>      'user_id' => array(
>       'rule' => 'notEmpty',
>       'message' => 'user must be valid',
>      ),
> 'email'=> array(
>                     'mustNotEmpty'=>array(
>                         'rule' => 'notEmpty',
>                         'message'=> 'Please enter email',
>                         'last'=>true),
>                     'mustBeEmail'=> array(
>                         'rule' => array('email'),
>                         'message' => 'Please enter valid email',
>                         'last'=>true)
>                     ),
>
>  );
>
> and this is what I have in a invitations controller:
>         $emails = array();
>
>         if(!empty($this->data['Invitation']['emails']))
>         {
>           $raw_emails = explode(',', $this->data['Invitation']['emails']);
>           foreach($raw_emails as $email)
>           {
>             $email = trim($email);
>             if(preg_match('VALID_EMAIL', $email)) // This is where I'm
> getting an error...
>               $emails[] = $email;
>           }
>
>  debug($email);
>
> I placed the debug in,... and I'm reading test email in the view,... but
> steel getting an error
>
>
>
> On Friday, November 2, 2012 6:52:42 AM UTC-7, chetan varshney wrote:
>
>> For email validation you should use-
>>
>> 'email'=> array(
>>                     'mustNotEmpty'=>array(
>>                         'rule' => 'notEmpty',
>>                         'message'=> __('Please enter email'),
>>                         'last'=>true),
>>                     'mustBeEmail'=> array(
>>                         'rule' => array('email'),
>>                         'message' => __('Please enter valid email'),
>>                         'last'=>true)
>>                     ),
>>
>> and for deep checking
>>
>> 'email'=> array(
>>                     'mustNotEmpty'=>array(
>>                         'rule' => 'notEmpty',
>>                         'message'=> __('Please enter email'),
>>                         'last'=>true),
>>                     'mustBeEmail'=> array(
>>                         'rule' => array('email', true),
>>                         'message' => __('Please enter valid email'),
>>                         'last'=>true)
>>                     ),
>>
>>
>>
>>  On Fri, Nov 2, 2012 at 7:05 PM, Chris <[email protected]> wrote:
>>
>>> hi guys,... I'm getting this preg_match Warning on Email issue no matter
>>> what I do,....
>>> can anyone help me please,....
>>>
>>> Warning (2): preg_match() [function.preg-match]: Delimiter must not be
>>> alphanumeric or backslash [APP/controllers/invitations_**controller.php,
>>> line 83]
>>>
>>> and this is what I have in a Model:
>>>
>>>     var $validate = array(
>>>       'email' => array(
>>>       'rule' => 'alphaNumeric',
>>>        'required' => true,
>>>       'allowEmpty' => false,
>>>      ),
>>>  );
>>>
>>> thanks in advance,...
>>>  chris
>>>
>>> --
>>> Like Us on FaceBook 
>>> https://www.facebook.com/**CakePHP<https://www.facebook.com/CakePHP>
>>> Find us on Twitter http://twitter.com/CakePHP
>>>
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "CakePHP" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to cake-php+u...@**
>>> googlegroups.com.
>>>
>>> Visit this group at 
>>> http://groups.google.com/**group/cake-php?hl=en<http://groups.google.com/group/cake-php?hl=en>
>>> .
>>>
>>>
>>>
>>
>>
>>
>> --
>> Chetan Varshney
>> Ektanjali Softwares Pvt Ltd
>>
>  --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>
>
>



-- 
Chetan Varshney
Ektanjali Softwares Pvt Ltd

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
Visit this group at http://groups.google.com/group/cake-php?hl=en.


Reply via email to