开发者

Adding capital letters in php email validation

I have used this pregmatch statement for validating email address

preg_match("^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$^", $partner_email)

If i use capital letters it will show an er开发者_如何学Goror.How i can change the pregmatch condition for supporting capital letters in email addres Thanks in advance


several ways:

1) change [a-z0-9_+-] to [a-zA-Z0-9_+] in all places

2) use preg_match("/^...$/i", $partner_emal) ... the /i flag makes it case-insensitive

3) use strtolower($partner_email) as the match string.


you can achieve it by adding i flag after the delimiter or as fourth parameter to preg_match()


One simple way is to just insist that the string is lower-case. This is probably preferable to mucking with (and perhaps debugging) a regex that you did not write and is known to work.

preg_match("^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$^", strtolower($partner_email))


Swap a-z for a-Z

10morechars....

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜