Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
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 constraints to numeric input fields. Say for example that you want to add an age constraint to a form element, so that someone has to be at least 13 years of age to submit this form. I'll switch back to my code, and under the age input field, I'll add a min value of 13.
I'm going to save that and go back into our page. I'll refresh my form. And now if I try to type in a value like nine. When I try to submit the form, it's going to tell me that the value has to be greater than or equal to 13. In the same way, the max field works to limit fields to a certain number. So I'll type in a max of 18. I'll save this. Back into our form, refresh, and now try to type in something larger than 18. Try to submit and I get a similar error. Now the cool thing about min and max is that you can control things like dates and date time. So, for example, if we wanted to limit the date for our reservations to only dates within the current work week, we could use a min and max value for that. So, let's see how that works.
I'm going to go back into my code and under the date input field I'm going to type in a minimum and a maximum value. I'll save this and I'll go back into my form, and I'll refresh. When I click on this input field, the calendar popup will only let me select dates within that time range. You can't always guarantee that the browser you're using is going to implement these attributes, so make sure you check out a website like caniuse.com and look for those attributes by typing them in. You may also want to test your forms in older browsers.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 101628 Viewers
61 Video lessons · 88383 Viewers
71 Video lessons · 72224 Viewers
56 Video lessons · 103971 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.