简体   繁体   中英

php - Warning: filter_var() [function.filter-var]: Unknown modifier '+'

I am trying to use a regular expression from http://www.regular-expressions.info/email.html , specifically:

[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?

However when using this along with:

filter_var($email, FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>$pattern)))

It brings up the error:

Warning: filter_var() [function.filter-var]: Unknown modifier '+'

Does anyone know how to fix this?

Your regexp is missing delimiters. Inserting, say, a semicolon before and after the pattern will fix this.

However, you should really use filter_var($email, FILTER_VALIDATE_EMAIL) instead of rolling out your own ( incorrect ) regexp.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM