Validating form field good headings for dating sites
Strictly speaking, you should make sure you're using the HTML5 DOCTYPE, otherwise you'll run into HTML validation errors.But the great thing about them is that they all degrade gracefully. If you want to customize this process, there are various places to make changes, each one serving a different purpose.
They also help with accessibility, as the text in the label will be read out to screen reader users: it can therefore be useful to indicate required fields by adding ‘required’ to the label text, as I’ve done above.A few months ago Sandeep introduced us to the HTML Constraint API, showing how we can use the new HTML5 input types and attributes to validate our forms in the browser with minimal Java Script.Today I’m going to walk you through validating a simple booking form by using the Constraint API, and keep an eye on how you can make sure your forms stay accessible too.As such, current best practice recommends supplementing the required attribute with the aria-required=”true” attribute: Now that our users get prompted to complete required fields, we need to make sure that the data they submit is in the format we require.
We'll want the 'Name' field to be submitted in the format 'Firstname Lastname', and to only contain letters and a space (NB in real world scenarios, you might need to take account of other locales – this example has been kept simple deliberately).Be careful when doing this in practice, since it can lead to confusing form output.