Form validation- Using JavaScript statement we can perform all required form field validations like empty textbox, the entered text is number/s or alphabet/s, etc.
E.g.
Check Output:
E.g.
<html>
<head>
<title>JavaScript form validation</title>
</head>
<body>
<center>
JavaScript Form Validation
<form name="form1">
Enter Name:<input type="text" name="elet">
Enter Roll No:<input type="text" name="roll">
<input type="button" onclick="check()" value="Check">
</form>
<script language="javascript">
function check()
{
x=document.form1.elet.value;
y=document.form1.roll.value;
if (/[^A-Za-z]/.test(x))
{
alert("Only Letter/s allowed in Name field")
}
else if(isNaN(y))
{
alert("Only number/s allowed in Roll No field")
}
else if(x==0 || y==0)
{
alert("Please fill all required information")
}
else
{
alert("Hi " + x + " Roll No: " + y + " How you Doing? \nIf you like this post then please \nshare it using share buttons \ngiven below")
}
}
</script>
</center>
</body>
</html>
Related Topics:
- JavaScript Introduction
- Variables in JavaScript
- JavaScript Function
- Accessing JavaScript Function
- Creating JavaScript interactive form
- Accessing form field value
- Creating interactive form login webpage
- Networking Fundamentals
- TCP/IP and Internet addressing
- Internet Working
- Internet Working Servers
- Concept and need for web publishing
- Web languages
- Javascript Control Structure
- Checking Text is Letter/s
- Checking Text is Number/s
- Checking Textbox is Empty or not
- Addition of two numbers
- Subtraction of two numbers
- Multiplication of two numbers
- Division of two numbers
- Form field validations
- Email validation