2

I am trying to come up with a valid pattern for an HTML form. I would like to allow all upper & lower case letters, spaces, numbers, and the symbols / \ @ # $ % & .

I've tried a couple different formats but I haven't had any luck.

So far I have:

<input type="text" name="Address" size="25"  pattern="[a-zA-Z0-9 ]{2,35}]" title="Title" required/>
TylerH
  • 20,799
  • 66
  • 75
  • 101
Robert
  • 53
  • 1
  • 1
  • 3

1 Answers1

7

This is an example I built with w3schools test page:

<!DOCTYPE html>
<html>
<body>

<form onsubmit="getElementById('s').innerHTML=getElementById('i').value;return false;">
  Country code: <input id="i" type="text" name="country_code" pattern="([a-zA-Z0-9]| |/|\\|@|#|\$|%|&)+" title="Three letter country code">
  <input type="submit">
</form>
<p>Submitted value: <span id="s">

Note: The pattern attribute of the input tag is not supported in Internet Explorer 9 and earlier versions, or in Safari.

You can use it to make your own tests at http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_pattern

Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
Alexander Jardim
  • 2,406
  • 1
  • 14
  • 22
  • 3
    Your regular expression pattern isn't quite correct. The correct one is `([a-zA-Z0-9]| |/|\\|@|#|\$|%|&)+`, or `[a-zA-Z0-9 /\\@#$%&]+`. – Toothbrush May 11 '14 at 15:38