JavaScript form validation

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.

<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>
Check Output: JavaScript form validation JavaScript Form Validation
Enter Name: Enter Roll No:


Related Topics:
  1. JavaScript Introduction
  2. Variables in JavaScript
  3. JavaScript Function
  4. Accessing JavaScript Function
  5. Creating JavaScript interactive form
  6. Accessing form field value
  7. Creating interactive form login webpage
  8. Networking Fundamentals
  9. TCP/IP and Internet addressing
  10. Internet Working
  11. Internet Working Servers
  12. Concept and need for web publishing
  13. Web languages
  14. Javascript Control Structure
  15. Checking Text is Letter/s
  16. Checking Text is Number/s
  17. Checking Textbox is Empty or not
  18. Addition of two numbers
  19. Subtraction of two numbers
  20. Multiplication of two numbers
  21. Division of two numbers
  22. Form field validations
  23. Email validation