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

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

Edit: I changed my mind, I will not use {0,20}, insted I will use strlen(). This:if (preg_match('/[a-z0-9]*@metu\.edu\.tr/',$_POST['email']) && strlen($_POST['email']) < 35)

+3
source share
2 answers

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

+12
source

Use this:

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

or that:

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

Presumably, there is an ideal regular expression for emails (assuming what you are 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

More details here .

+2
source

All Articles