JavaScript Input Field Validation Function with Input field color highlight and Error Message Display
We use a lot of Forms regularly. If you are using a Form in your website, have you ever tried to create some validations on the form so that the inputs made by user can be checked? There are a lot of libraries out there which can help you do the input validation using JavaScript, but that is additional code that needs to be included, and third party libraries can often slow down your page load speeds. Today, we'll write a small JavaScript function that we can include in our website and which does the input validation very quickly and efficiently. This function also highlights the input field in a color of your choice, and you can display an error message to your end user. If you have a form with multiple fields, and want to run validations on all of them, you'll have to loop through the fields one by one using a for loop, and run the validation on each one. You can pass the field ID to the function and run the validation on it. Below is our function which will d...