Reputation: 87
I am creating a form in html and for my first and last name text inputs, I want to have a regex validation on them that only allows the user to input: letters of the alphabet, spaces, and hyphens.
I have tried this pattern but to no avail:
[A-Za-z -]
My HTML code:
<input type="text" id="first_name" name="first_name" maxlength="25" required="required" pattern="[A-Za-z -]"/>
I know how to get only alphabet characters, but allowing spaces and hyphens only is something I'm unable to manage.
Upvotes: 2
Views: 25827