I would like to let my users paste a string of emails into a text are and on submit import them into a db table.
It seem that the typical syntax for email and they way it is usually typed in TO field is:
"Fname Lname" <abc@email.com>, "Fname Lname" <abc@gmail.com>,
I suppose on submit I need to parse it through some loop. How do I detect the name/email pair break? Is there a way to also do some basic email validation?
UPDATE:
I realized that sometimes the string can be slightly off, like missing a name:
Fname Lname" <abc@email.com>, abc@gmail.com,
or even
<abc@email.com>, abc@gmail.com,
or even
abc@email.com, abc@gmail.com,
How to make it more robust and note break if a name is missing? The email should be there all the time! Otherwise it just needs to ignore an instance and move on to the next contact. But I guess I can do that validation after the array of contacts is created…
I am not good in
preg_match, so I tried it in another way. If your string is always in this pattern, you can try something like this:Test Here
EDIT:
(Change in input string)
Test Here