Thursday, January 19, 2017

Lab 9: Validation

This is lab 9 where we have to create a form using JavaScript Validation to validate whether the input is correct or not. First we have to create a form with a legend that states the title of this form. In this case, the legend is Your information. Within the form, it will have a first name, last name, age, day of birth, phone number, and email. The difficult part is to use JavaScript to make it work and make it validate whether if the input is correct using boolean and if/else statements.

First I wanted to make every box require to be answered. So I would use: 


 if(something.checkValidity() == false){
    document.getElementById("a").innerHTML = something.validationMessage;}

this will write a message out saying that the information needs to be entered. After I did that for each, I also make it say thank you when you enter the correct input to the box. This is all the basic validations for the names. For the age, I also added a maximum number to 130 and minimum of 0. If the user enters anything outside of this range, it will notify the user. Also if the user enters an age under 18, it will say that the user is a kid, if it's over 18 then it will say the the user is an adult. We all know that we use 2 "/"s while listed birthdays so most of the time. And that is the validation for the birthdays, it must include 2 "/"s. For the phone number, I gave it a validation of a minimum number of 1000000000 and a maximum of 99999999999, because phone numbers are always between 10-11 digits and this includes all numbers that are 10 to 11 digits. And last, for the e-mail, I made a validation to require the "@" symbol and the "." because an e-mail can not exist without these two symbols.

No comments:

Post a Comment