From the course: Validating and Processing Forms with JavaScript and PHP

Unlock this course with a free trial

Join today to access over 22,500 courses taught by industry experts.

Constraining numeric and date fields

Constraining numeric and date fields

Some numeric fields have attributes that let you control the number of characters as well as the minimum and maximum value. These will even work with dates. So, I have a simple form here, where I'm asking the user a name, age, and when they would like to make a reservation. You can have the browser prevent the user from typing fields longer than a certain length. With a maxlength attribute that works for fields like text, email, search, password, telephone or url. We can for example make sure that their name is no longer than ten letters, perhaps our database limits the length of that field. We'll see how that works, we'll go into our code for this page and modify the name input field, so that it has a maxlength we'll make it ten characters. So I'll save this, I'll go back to my form, Refresh, and when I try to type in something longer than ten characters, the browser will stop me at ten characters. Some other attributes that you can use are min and max. They let you create…

Contents