Validating form input javascript

Rated 3.82/5 based on 772 customer reviews

It also means that if you click the label, the associated input tag receives the focus.

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).To make sure our user enters the right data in the email, website, and number of tickets fields, we can use some of the new input types added in HTML5: By specifying the appropriate type, our browser will validate the data for us and make sure we've got an email address in the email field, a URL in the website field, and a number in the number of tickets field.Note too that the If the user enters anything less than 1 or greater than 4, they'll be prompted to enter a number in the permitted range.I’m also using the WAI ARIA attribute now, so if we leave ‘required’ in the label tag screen reader users will have ‘required’ read to them twice, which they could find rather annoying.A word of warning though: not all browsers implement the attribute accessibly, so it might not be picked up correctly in certain browser / screen reader combinations.

Leave a Reply