开发者

email validation using regular expression

i am using this regular expression for email validation but it is not allowing hyphen (-):

/^\w+([\.-_]?\w+)*@\w+([\.-_]?\w+)*(\.\w开发者_高级运维{2,4})+$/

please any one tell me how can i do this?


There is a function in PHP for this filter_var, would try to avoid using RegEx as much as posible. They are powerful but can get pretty hairy.

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


try escaping your hyphens:

/^\w+([.\-_]?\w+)*@\w+([.\-_]?\w+)*(.\w{2,4})+$/

the dash is reserved for ranges inside square brackets so if you want to make it a literal, you need to escape it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜