I want to validate a string which can be an email or multiple emails separated by commas.
For example:
bill.gates@hotmail.com -> TRUE
bill -> FALSE
used this for php preg_match_all()
$pattern = '/([\w+\._%-]+@[\w+\.-]+\.[\w+]{2,4}[^,;\s])/';
$text = 'abc@efg.com, efg, hij@emg.com, ak@efg asfbd@efg.com ab@sdfs.com abc+efg@pqr.com';
preg_match_all($pattern, $text, $match);
var_dump($match);
array(2) {
[0] =>
array(5) {
[0] =>
string(11) "abc@efg.com"
[1] =>
string(11) "hij@emg.com"
[2] =>
string(13) "asfbd@efg.com"
[3] =>
string(11) "ab@sdfs.com"
[4] =>
string(15) "abc+efg@pqr.com"
}
[1] =>
array(5) {
[0] =>
string(11) "abc@efg.com"
[1] =>
string(11) "hij@emg.com"
[2] =>
string(13) "asfbd@efg.com"
[3] =>
string(11) "ab@sdfs.com"
[4] =>
string(15) "abc+efg@pqr.com"
}
}