0

I am developing an API using Codeigniter an Phils RESTserver. In one of the resources the developer can send in an "array" of email addresses that then gets processed on the server.

How can I, perhaps using regex, check that the incoming "array" is in the format as you can see below? I will use this as a CI Form validation.

("[email protected]","[email protected]")

Thankful for all help!

5
  • Again, maybe it would be much more convenient to pass an array, rather than pass this custom string, validate it with regexes and split into array?
    – J0HN
    Aug 18, 2011 at 12:16
  • How will that be done? The validation and the format of the array. Aug 18, 2011 at 12:52
  • Post your code that perfroms backend request. Without knowing how you are sending requests little can be done.
    – J0HN
    Aug 18, 2011 at 12:53
  • I am posting through Firefox plugin RestClient. On the server side I got this pastie.org/private/xsc4be8pkiugls4wroiuvq Aug 18, 2011 at 13:18
  • Well, if you are posting it in request body like addresses ("[email protected]","[email protected]") you may replace it with addresses[] "[email protected]" *newline* addresses[] "[email protected]", so you'll be able to extract this with $_POST['addresses'] as an array. Alternative syntax addresses ["[email protected]","[email protected]"]
    – J0HN
    Aug 18, 2011 at 13:51

1 Answer 1

0
foreach ($this->post('emails') as $email)
{
     if ( ! filter_var($email, FILTER_VALIDATE_EMAIL))
     {
         return $this->response(array('message' => 'GTFO'), 400);
     }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.