I'm trying validate Gmail username by using their self rule on create account page.
There are the rules:
Expecting results:
.carlos.so@gmail.com - invalid
carlos.so.@gmail.com - invalid
carlos..so@gmail.com - invalid
carlos_so@gmail.com - invalid
carlos.so@gmail.com - valid
Already tried the pattern above but without success:
(?!\.)[a-zA-Z_.]{6,30}(?!.*\.)
You could use:
^[a-zA-Z0-9](?=[a-zA-Z0-9.]{5,29}@)[a-zA-Z0-9]*(?:\.[a-zA-Z0-9]+)*@gmail\.com$
^
Start of string[a-zA-Z0-9]
Match a single char a-zA-Z0-9(?=[a-zA-Z0-9.]{5,29}@)
Assert 5-29 allowed chars to the right followed by @[a-zA-Z0-9]*
Match optional chars a-zA-Z0-9(?:\.[a-zA-Z0-9]+)*
Optionally repeat matching .
and 1+ allowed chars@gmail\.com
Match @gmail.com
$
End of stringSee a regex101 demo.