dimanche 8 novembre 2020

HTML5 / Regex: Allow unicode letters and spaces (only working for letters)

I want to use the HTML5 pattern attribute with a Bootstrap form validation and only allow Unicode letters (uppercase and lowercase) and spaces.

As for the unicode letters my pattern works but as soon as I try to include spaces it doesn't work anymore and then allows all characters including numbers and special signs etc. For the whitespace I tried a simple space as well as \s but both didn't work for me.

How can I extend the below to also accept spaces ?

<input type="text" class="form-control rounded4 modalField" id="lastName" name="lastName" pattern="^[A-Za-zÀ-Žà-ž][A-Za-zÀ-Žà-ž.-]*$" required>

Many thanks in advance,
Tom

Aucun commentaire:

Enregistrer un commentaire