HTML5 form validation pattern alphanumeric with spaces?
Solution 1:
How about adding a space in the pattern attribute like pattern="[a-zA-Z0-9 ]+"
.
If you want to support any kind of space try pattern="[a-zA-Z0-9\s]+"
Solution 2:
My solution is to cover all the range of diacritics:
([A-z0-9À-ž\s]){2,}
A-z
- this is for all latin characters
0-9
- this is for all digits
À-ž
- this is for all diacritics
\s
- this is for spaces
{2,}
- string needs to be at least 2 characters long
Solution 3:
To avoid an input with only spaces, use: "[a-zA-Z0-9]+[a-zA-Z0-9 ]+"
.
eg: abc | abc aBc | abc 123 AbC 938234
To ensure, for example, that a first AND last name are entered, use a slight variation like
"[a-zA-Z]+[ ][a-zA-Z]+"
eg: abc def