Uploaded by john doe

myan

advertisement
REPORT ON FORM VALIDATION
St. Xavier’s College
Maitighar, Kathmandu
Nepal
Submitted by:
Name: Ajay Karki
Class: 12 “G”
Roll: 310
Submitted to:
Mr. Jay Sundar Shilpakar
Lecturer
Department of Computer Science
23rd Feb, 2023
1. JavaScript Form Validation
Data validation is the process of ensuring that user input is clean, correct, and useful. t is
important to validate the form submitted by the user because it can have inappropriate values.
So, validation is must to authenticate user. JavaScript provides facility to validate the form on the
client-side so data processing will be faster than server-side validation. Most of the web
developers prefer JavaScript form validation.
Through JavaScript, we can validate name, password, email, date, mobile numbers and more
fields. Typical validation tasks are:
● Has the user filled in all required fields?
● Has the user entered a valid date?
● Has the user entered text in a numeric field?
Most often, the purpose of data validation is to ensure correct user input. Validation can be
defined by many different methods, and deployed in many different ways.
1. Server side validation
It is performed by a web server, after input has been sent to the server.
2. Client side validation
It is performed by a web browser, before input is sent to a web server.
2. Types of methods
Form validation is an essential task in web development to ensure that user input is correct,
complete, and secure. JavaScript provides various methods to perform form validation. Some of
the common methods are:
● Regular Expression Method
● Index Of() Method
● Others
a) Regular Expression Method:
Regular expressions are patterns used to match character combinations in strings. They
can be used to validate various types of inputs like email, phone number, password, etc. Here is
an example of validating an email address using regular expressions:
b) IndexOf() Method:
The indexOf() method returns the position of the first occurrence of a specified value in a
string. It can be used to check if a specific string or character exists in the user input. Here is an
example of checking if a string contains only letters and spaces:
c) Others:
Other methods for form validation include using regular JavaScript expressions such as isNaN()
to validate numbers, checking if the input is empty or not, or using built-in HTML5 form
validation attributes such as required and pattern. Additionally, JavaScript libraries and
frameworks such as jQuery, React, and Angular provide their own form validation methods.
Examples of Form Validation in JavaScript
Name and Password:
We are going to validate the name and password. The name can’t be empty and password
can’t be less than 6 characters long.
Here, we are validating the form on form submit. The user will not be forwarded to the next page
until given values are correct.
Download