0

I have two input fields that should only allow these characters to be submitted:

  1. Alpha characters
  2. Apostrophes
  3. Hyphens
  4. Whitespaces

I can add the first three to the pattern with no problems, however, when I include whitespaces, the pattern attribute does not work at all. Anything and everything will be accepted.

How can I include whitespaces into my pattern?

https://codepen.io/harlessmark/pen/BaZJYMa

<form>
  <input
    type="text"
    placeholder="[a-zA-Z'-\s]+"
    pattern="[a-zA-Z'-\s]+"
    title="Only letters, hyphens, apostrophes, and spaces are permitted"
  >
  
  <button type="submit">
    Submit
  </button>
</form>
Mark
  • 169
  • 1
  • 1
  • 10

0 Answers0