How to fix pattern=”[A-Za-z]” input field

Hey for some reason when i use this(pattern=”[A-Za-z]”) in my input field nothing will be accepted?

When I enter “Ruben” in this field it just says “make sure the format complies with the requested format”?
Thank you for your help

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

The pattern matches exactly one character. Add a + quantifier after the character class to make it match one or more of those characters.

Method 2

The reason is that [A-Za-z] matches single character, Ruben is 5 hars long.

You should use [A-Za-z]+ for pattern instead, which will accept one or more of letters.

You could also use anchors ^[A-Za-z]+$ to make sure input consists of only letters.

<form>
  <div>
    <label for="uname">enter test string </label>
    <input type="text" id="uname" name="name" required size="45"
           pattern="^[a-zA-Z]+$" title="enter test string">
    <span class="validity"></span>
    <p>Input must be at least one letter and ocnsist of only letters.</p>
  </div>
  <div>
    <button>Submit</button>
  </div>
</form>


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x