Help with Email Input Regex in HTML

0
13
Asked By CuriousCat42 On

I'm trying to use the HTML email input type along with the pattern attribute for the first time. However, I'm running into an invalid regex error in Firefox, even though my regex works perfectly fine when tested on regex101.com. Initially, I'm using a simple regex to get it working, and then I'll move on to my custom regex. Here's my HTML code I'm working with:

``

When checking in Firefox v142.0, I get the error:

`Unable to check because '/[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,}$/' is not a valid regexp: invalid character in class in regular expression`

Can anyone offer some guidance on how to resolve this?

4 Answers

Answered By SyntaxSlinger On

Yeah, and even if it seems solid, regex emails can often fail. Checking via email verification is much more reliable and it avoids the hassle of complicated regex patterns.

Answered By PracticalDeveloper21 On

You're correct to consider regex, but don’t forget that it won’t cover all possibilities—email formats can be tricky! Why not implement an email confirmation instead? It’s straightforward and ensures the address is reachable.

Answered By RegexWizard99 On

It looks like the problem is with the last `-` in your character class `[a-z0-9.-]`. Make sure to escape it properly. You should change that part to avoid confusion. Try this corrected version: `[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,}$`.

Answered By EmailEnthusiast77 On

Just a heads up, regex isn’t the best way to validate emails. There are so many edge cases that can lead to false negatives. It’s safer to validate by sending an actual email verification link!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.