user3117337
user3117337

Reputation: 223

HTML5 pattern allow specific special characters

I have an input text field in my form but i don't know how to filter the input that can all letters and special characters but will not accept numbers.

   <input  pattern="[A-Za-z]{1,25}" maxlength="25" type="text" required="required" style="height:20px"  value="">

It doesn't accept when i enter my middle name "pacaña"

how could i alter the pattern that can accept all characters/special-characters and other special characters like ñ?

Upvotes: 5

Views: 52953

Answers (4)

Ulysse Widmer
Ulysse Widmer

Reputation: 1

I crashed into the same problem, wanted to allow french accents into a text field... After a bit of trial and error, turns out you can use pattern="^[\p{L}]${1,25} to allow ASCII letters and Unicode variants, accented letters and special characters.

Upvotes: 0

Isuru Dinusha
Isuru Dinusha

Reputation: 51

Allow any special symbols : [A-Za-z\W+]

 <form action="/action_page.php">
      <label for="country_code">Special Symbols Not Allowed:</label>
      <input type="text"  pattern="[A-Za-z]{1,25}" title="Special characters are not allowed!"><br><br>
      <input type="submit">
    </form>

<br><br>

<form action="/action_page.php">
      <label for="country_code">Special Symbols Allowed:</label>
      <input type="text"  pattern="[A-Za-z\W+]{1,25}" title="Special characters are not allowed!"><br><br>
      <input type="submit">
    </form>

Upvotes: 0

Curtis Blackwell
Curtis Blackwell

Reputation: 3207

pattern="[^0-9]*"
  • […] matches a single character
  • ^ anything except the following (when within [])
  • 0-9 digits zero through nine
  • * between zero and unlimited times

Upvotes: 10

user4584103
user4584103

Reputation:

For Not allowing Specific Symbols (dont allow , or .)

<form>
<input type="text" pattern="[^-,]+" title="'-' is not allowed">
<input type="submit">
</form>

Upvotes: 3

Related Questions