I am using the following regex to validate emails and just noticed some problems and don't see what the issue is :
/^[a-z0-9_.-]+@[a-z0-9.-]+.[a-z]{2,6}$/i.test(value)
support@tes is invalid
support@test is valid
support@test.c is invalid
support@test.co is valid
the 2,6 is for requiring and ending tld between 2 or 6 and that does not appear to be working either. I am sure I had this working properly before.
In a regex, .
is a wildcard (meaning any char). you need to escape it as \.
Keep in mind though, the regex is too restrictive. You can have non-alpha numeric chars in the address, like '
I notice you're not escaping the .
. There might be more to it than that, but that jumps out at me.
This is a decent check for an e-mail with Regex
\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
However you may want to read this. Using a regular expression to validate an email address
There are many ways to regex an email address. depending on how precise and restrictive you want it, but to re-write a working regex closest to what you have in you question. This should work:
^[\w_.-]+@[\w]+\.[\w]{2,6}$
support@tes - Invalid
support@test - Invalid
support@test.c - Invalid
support@test.co - Valid
supp34o.rt@tes.com - Valid
But also keep in mind ALL the characters allowed in a valid email address - What characters are allowed in an email address?