开发者

Limit [a-z0-9]* to 20 characters?

I can get the [a-z0-9]* part from [a-z0-9]*@example.com with regex but I want to limit the [a-z0-9]* part with 20 characters. Is it possible with regex?

Edit: I have changed my mind, I'll not use {0,20}, insted I'll use strlen(). This one: if (preg_match('/[a-z0-9]*@metu\.edu\.tr/',$_POST['email']) && strlen($_POST['email'])开发者_运维百科 < 35)


[a-z0-9]{0,20}@example.com will limit it to 0 to 20 characters.


Use this:

[a-z0-9]{0,20}@example.com

or this:

[a-z0-9]{1,20}@example.com

Supposedly, there is a perfect regex for emails (assuming that's what you're trying to do) that was recently discovered:

/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i

Read more here.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜