Form Validation Using Javascript For Registration

Bipsmedium
1 min readJun 10, 2021
Form Validation Using Javascript For Registration

In this tutorial, we will learn the form validation using javascript for registration. Sometimes, HTML forms in web pages or any other forms are built to prevent the users to submit the form data to know whether the data or information entered by the users are correct or not.

If the information is correct then the form will allow the user to proceed further. We can do this with the help of a javascript event handler.

Also Read, auto calculate the sum of input values with javascript

Required Steps of validating an HTML form using Javascript

  • We will use the onsubmit event to validate the input fields and onsubmit event occurs after form data is submitted and it is handled by the web browser.
  • We will use the name attribute of the form and the name attribute of the input fields and combine both the attributes to get the input values.
  • Now, we will store it in a variable and check whether the variable is empty or not. If empty then we can validate the input fields as shown below

var fname = document.forms["userform"]["fname"].value;

if(fname == ''){

window.alert('Please enter the first name');

return false;

}

Complete Code:-

Conclusion:- I hope this tutorial will help you

--

--

Bipsmedium

Hi, This is Biplab and I am a PHP laravel developer and other open source technologies. I am here to share my experience with the community.