i am stuck at particular problem i have username field where on only alphabets numbers and . – and _ are allowed and should always start with alphabet
here are examples what are accepted
someone@mydomain.com
something1234@mydomain.com
someething.something@mydomain.com
something-something@mydomain.com
something_something@mydomain.com
something_1234@mydomain.com
something.123@mydomain.com
something-456@mydomain.com
what i have done till now is
[a-zA-Z0-9]+[._-]{1,1}[a-zA-Z0-9]+@mydomain.com
this matches all my requirement except of problem it dosent match
someone@mydomain.com
someont123@mydomain.com
but it even matches
someone_someone_something@mydomain.com
which is not required i am really not getting how to solve this one thing i tried is
[a-zA-Z0-9]+[._-]{0}[a-zA-Z0-9]+@mydomain.com
but this is also not solving my problem now it accepts everything like
something+455@mydomain.com
which is not required please help me
If you want to make the
-or.optional, then you have to replace the{1,1}(quantifier: once) with an?(quantifier: one or none) here:The reason this regex also matches shorter addresses without delimiter
-._is that you don’t assert the whole string, but just some part of it. Use start^and end$anchors: