Unit3 JS Form Validation
Unit3 JS Form Validation
validation
2 Data Validation
Data validation is the process of ensuring that user input is clean, correct,
and useful.
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.
Server side validation is performed by a web server, after input has
been sent to the server.
Client side validation is performed by a web browser, before input is
sent to a web server.
<script>
function myFunction() {
// Get the value of the input field with name="numb"
let x = myForm.name.value;
let text;
//isNaN() returns true if a value is NaN not a number
if (isNaN(x) || x< 1 || x > 10)
{
text = "Input not valid";
}
else
{
text = "Input OK";
}
document.write(text);
Dr. Anupama Jha
}
</script></body></html>