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
- email@email.com.eu
- email@example.example.audio
- test@code.email.eu
- example-test@test.email.eu
- test@code-test.com.eu
these are invalid emails:
- email@em
- email@example.
- test@.code.em.eu
- test@ui.de.
- example.@test.email.eu
- test@-code.example.eu
- test@testmail.com.eu.audio
- code.@code.com
- .test@code.com.audio
- .test@code.com.audio.
- -test@test.code.audio
- -test@test.code.audio-
- 87-code@test-.hi.code
- test/input@test-.com.ar
- ,test@code.com.eu
- email @test.com.eu
- email @test.com.eu