Skip to content

Instantly share code, notes, and snippets.

@leeprobert
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leeprobert/d34ab00a528be7fef055 to your computer and use it in GitHub Desktop.
Save leeprobert/d34ab00a528be7fef055 to your computer and use it in GitHub Desktop.
A bunch of things that are useful in a HTML5 form
<!-- Regular expression for UK postcodes -->
<label for=postcode>Postcode<span class="red">*</span></label>
<input name=postcode type=text aria-required required pattern="[0-9]{5}(\-[0-9]{4})?|[a-zA-Z]{1,2}\d{1,2}\s?\d[a-zA-Z]{1,2}" placeholder="A valid UK postcode" />
<!-- to test in the browser console use: -->
/^(:?[a-zA-Z]{1,2}\d{1,2}\s?\d[a-zA-Z]{1,2})$/.test("tn12 6an")
/* force webkit search field to look like normal textfield */
input[type="search"] {
-webkit-appearance: textfield;
}
/* validation */
input[type="text"]:focus:invalid, input[type="email"]:focus:invalid {
box-shadow: 0 0 5px $red;
border-color: $red;
}
input[type="text"]:focus:valid, input[type="email"]:focus:valid {
box-shadow: 0 0 5px $green;
border-color: $green;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment