Email "list" validatator
Email "list" validatator
Hey
First of all, thank you for the excellent program for the datatables editor. I love this program and it is about to bring more kick to my programming.
My problem is checking the multiple email address format.
I have New Email form to put emails-addresses to multiple recipients, like CC and BCC.
I use the following validation code...
Field::inst( 'email' )
->validator( Validate::email(
ValidateOptions::inst()
->allowEmpty( false )
->optional( false )
) );
But I need checking for multiple email addresses validation so array(), and this validation check only one address.
So i need to check list, like: name1@company.fi; name2@company.fi; name3@company.fi; name4@company.fi;
I use datatables editor DataTable --> Create New entry
Thanks and sorry my poor english language...
Replies
Hi,
What you would need to do is create a custom validator. It would split the string on the semi colon, and then use PHP's built in e-mail validation to check that each one is a valid address (in a
for
loop).Allan
Thanks for this!
I like examples. So here is one implementing Allan's suggestion. The user may enter either nothing or a comma / semi colon separated list (for the Germans) of email addresses. I only save a comma separated list etc.
outside of the Editor instance: error messages:
The Field instance with validator and set formatter: