Ely94
Ely94

Reputation: 81

form with input attributes 'required' and 'pattern' doesn't work

Hi i have this code with HTML5:

<form id="pay" method="GET" class="row g-3" style="display:none;" type="hidden">
  <strong>Date</strong></a><br>
  <div class="col-md-10">
    <label for="name_users_card" class="form-label">user card</label>
    <input type="text" class="form-control" id="name_users_card"
           pattern="^[A-Za-zèòà\s]$"
           minlength="3"
           maxlength="20"
           placeholder="titolare carta"
           title="take a valid name" required/>
  </div>
</form>

When I try to run the code, the required control is not working. Why?

Upvotes: 0

Views: 59

Answers (2)

Rounin
Rounin

Reputation: 29453

Your Regular Expression Pattern:

^[A-Za-zèòà\s]$

is a single character.

If you want zero to any number of characters, use:

^[A-Za-zèòà\s]*$

If you want one to any number of characters, use:

^[A-Za-zèòà\s]+$

If you want exactly twenty characters, use:

^[A-Za-zèòà\s]{20}$

If you want three to twenty characters, use:

^[A-Za-zèòà\s]{3,20}$

If you want three to any number of characters, use:

^[A-Za-zèòà\s]{3,}$

Upvotes: 1

lambsbaaacode
lambsbaaacode

Reputation: 70

don't actually understand the problem but you have an incomplete <a> tag and you made your form hidden by setting display:none;

Upvotes: 2

Related Questions