<label for="post-code-1">Post code 1<span><sup>required</sup></span></label>
<input type="text"
name="post_code_1"
id="post-code-1"
pattern="^[A-Z]{1,2}[0-9][0-9A-Z]?\s?[0-9][A-Z]{2}$"
placeholder="e.g. SW12 1AA, LN8 1DC"
required>
<label for="post-code-2">Post code 2 <span><sup>required</sup></span></label>
<input type="text"
name="post_code_2"
id="post-code-2"
pattern="^[A-Z]{1,2}[0-9][0-9A-Z]?\s?[0-9][A-Z]{2}$"
placeholder="e.g. SW12 1AA, LN8 1DC"
required>
<pre>
<b>Examples of Valid UK Postcodes:</b>
SW1A 1AA
B1 1BB
B11BB
EC15 1AB
W1A 0AX
M1 1AE
CR2 6XH
<b>Examples of Invalid UK Postcodes:</b>
12345 (No letters, incorrect format)
B12 1bb (Lowercase in second part of postcode)
SW1 1AA (Too many spaces)
SW1A-1AA (Invalid character -)
M1 AE (Missing a digit in the second part)
AB10 CD12 (Incorrect space and sequence of characters)
</pre>
<style>
label {
display: inline-block;
margin: .5rem 0 .15rem 0;
}
label span {
color: red;
}
input[type="text"] {
display: block;
border: 2px solid green;
background-color: lightgreen;
background-image: linear-gradient(to right, lightgreen, limegreen);
font-size: 1rem;
padding: .15rem .5rem;
transition: all 250ms ease;
}
input[type="text"]::placeholder {
font-size: 70%;
letter-spacing: 0;
transition: all 550ms ease;
}
input[type="text"]:focus {
border-color: grey;
background-color: lightgrey;
background-image: linear-gradient(to right, lightgrey, grey);
/*animation: pulse-shadow 1.45s infinite ease-in-out;*/
}
@keyframes pulse-shadow {
0% { box-shadow: 0 0 1px 2px grey; }
50% { box-shadow: 0 0 1px 3px black; }
100% { box-shadow: 0 0 1px 2px grey; }
}
input[type="text"]:focus::placeholder {
color: transparent;
letter-spacing: 2rem;
}
input[type="text"]:invalid:not(:focus) {
border-color: red;
background-color: lightpink;
background-image: linear-gradient(to right, lightpink, lightcoral);
}
</style>