开发者

Full name with valid email

$string ='"Test User" <test@test.com>,"Another" <another@test.com>,"aeer" <whateveryourmail@gmail.com>';

I've succeed splitting this become pair of name and email address with this code

preg_match_all('!"(.*?)"\s+<\s*(.*?)\s*>!', $string, $matches);

the problem is, I can't validate the email address,false email address will be match too. How开发者_JAVA百科 to filter only valid email and also splitting Name and email address?


You could use some of the available mail address parsers available, e.g.:

  • mailparse_rfc822_parse_addresses()
  • Mail_RFC822::parseAddressList()

Optionally, filter the output through filter_var() (or one of its permutations targeted at arrays) with the FILTER_VALIDATE_EMAIL.


E-mail address validation can be done in two ways: check for a @ and a . and assume it's valid. Users know their e-mail address, it is not our business if they enter a wrong one. If you want to be certain you make a good e-mail address checker, then there is only one correct regex to use for validation: http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html


What about jQuery?

http://plugins.jquery.com/project/jqueryvalidate

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜