HTML 5 Form Validation

Recently I’ve been starting to utilise the pattern attribute in form input fields to ensure that what the user enters is what is expected. I see so many mistakes coming through with a capital O instead of a zero 0, or spaces within email addresses. Working for a recruitment agency, I need to ensure that the NI Number and postcode are correct to send to HMRC, and I also need a valid email address for registration to our training system, plus to email out payslip and timesheet alerts.

So, I’ve added a CodePen with the HTML5 form validation that I’ve been using on a couple of forms, save me looking through files for the regex’s again. There’s only a few on there at the moment – UK postcode, email and National Insurance number, but I’ll probably add more as I need to. Feel free to suggest others 🙂

View the code – HTML5 Form Validation.

You may also like...