How can I make this regular expression work?
To validate emails, my regular expression is supposed to be fine, but I use it in the html pattern and I see in the console that it throws me this error: email.php:1 Pattern attribute value ^(?!.*([.-])\1)(?!.*([.-])$)(?!.*[.-]$)(?!.*[.-]{2})[a-zA-Z0-9_%+-][a-zA-Z0-9._%+-]*@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ is not a valid regular expression: Uncaught SyntaxError: Invalid regular expression: /^(?!.*([.-])\1)(?!.*([.-])$)(?!.*[.-]$)(?!.*[.-]{2})[a-zA-Z0-9_%+-][a-zA-Z0-9._%+-]*@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/v: Invalid character in character class
, I don't know where the error is and the check with https://regex101.com/ and according to my expression it has no errors, could you tell me where the error is, or what I missed or what change that I did not realize over time, I am using google chrome as a browser.
The regular expression I use is this:
<input type="email" pattern="^(?!.*([.-])\1)(?!.*([.-])$)(?!.*[.-]$)(?!.*[.-]{2})[a-zA-Z0-9_%+-][a-zA-Z0-9._%+-]*@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$" />
here is just the regular expression:
^(?!.*([.-])\1)(?!.*([.-])$)(?!.*[.-]$)(?!.*[.-]{2})[a-zA-Z0-9_%+-][a-zA-Z0-9._%+-]*@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
these are valid emails
these are invalid emails:
- email@em
- email@example.
- [email protected]
- [email protected].
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected].
- [email protected]
- [email protected]
- [email protected]
- test/[email protected]
- ,[email protected]
- email @test.com.eu
- email @test.com.eu