SLC
SLC

Reputation: 13

HTML input pattern

I am using the input pattern on my register form which consists of a Username, Email and Password.

I have set the Username between 5 and 15 characters however when this has been typed correctly and I go to submit the form I am not able to submit, but instead still receive the required title message. Anyone any ideas?

<div class="col-sm-offset-2 col-sm-9"><td><input pattern=".{5, 15}" required title="Username should be between 5 - 15 characters"type="text" class="form-control" name="uname" placeholder="User Name" required/></td> </div>

Upvotes: 0

Views: 110

Answers (3)

fonfonx
fonfonx

Reputation: 1465

Remove the space before 15: pattern=".{0,15}"

Upvotes: 1

Quentin
Quentin

Reputation: 943510

You must remove the space. Compare the explanations from https://regex101.com/

 /.{5, 15}/
  • . matches any character (except newline)
  • {5, 15} matches the characters {5, 15} literally

and

 /.{5,15}/
  • .{5,15} matches any character (except newline)
  • Quantifier: {5,15} Between 5 and 15 times, as many times as possible, giving back as needed [greedy]

Upvotes: 1

Agu V
Agu V

Reputation: 2281

You could try this pattern, it works in this fiddle

pattern=".{5,15}$" 

Upvotes: 1

Related Questions