im relatively new to WebDevelopment. Basically, I have an application where I want to allow only alphabetical letter a-z and A-Z and the – special character for double names like Marry-Jane in the “name” input field.
Normally there are multiple options to do that with regex. 2 Examples what I've tried.
^[^\/():.;,\\=\[\]]*$
^[a-zA-Z0-9àáâäãåąčćęèéêëėįìíîïłńòóôöõøùúûüųūÿýżźñçčšžÀÁÂÄÃÅĄĆČĖĘÈÉÊËÌÍÎÏĮŁŃÒÓÔÖÕØÙÚÛÜŲŪŸÝŻŹÑßÇŒÆČŠŽ∂ð-]+$
Both of those Options are probably not ideal but are working fine when I use them in the Backend or test them with some basic regex pages like regex101.
But as soon as I use them on the “pattern” attribute of an input field they both stop working properly. I’m still allowed to submit the form even if the input doesn’t match the regex pattern and I have no glue where the mistake is located.
Inputs examples I tested:
Hallo123() //should not work Marry-Jane //should work Marry()Jane //should not work
All of those inputs still get submittet and as I mentioned before I got no glue why its not working
Example input (works out great with simple patterns like: "^[a-zA-Z]+$"):
<input type="text" id="firstname" name="firstname" pattern="^[^\/():.;,\\=\[\]]*$"><br><br>
Also tried the pattern provided in the comments here: The form still gets submitted
<form>
<input type="text" id="lastName" name="lastName" pattern="[^/():.;,=\][]*">
<input type="submit">
</form>