PHP - Email Validation [duplicate]

别等时光非礼了梦想. 提交于 2019-12-11 03:25:07

问题


Possible Duplicate:
email address validation

Hello. I have this function to validate an email address

function isValidEmail($email){
 return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);
}

It works well with domain zones like .com, .us etc, which contain from 2 to 3 symbols after a dot. My question is: is it important to include such zones as .info or .travel with length more than 3 symbols and should I worry about multiple .co.uk etc.? How to improve the function for these needs?


回答1:


there is a native function in php to do this, test it and see if it fits your needs:

var_dump(filter_var('bob@example.com', FILTER_VALIDATE_EMAIL));

P.S: Isn't eregi() deprecated?



来源:https://stackoverflow.com/questions/4906608/php-email-validation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!