Advertisement
Hydrase

Driving Validation

Jun 7th, 2025
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Driving Licence Application</title>
  5. <script>
  6. function validateForm() {
  7. var name = document.getElementById("name").value.trim();
  8. var address = document.getElementById("address").value.trim();
  9. var bloodGroup = document.getElementById("bloodgroup").value;
  10. var dob = document.getElementById("dob").value;
  11. var mobile = document.getElementById("mobile").value.trim();
  12. var aadhar = document.getElementById("aadhar").value.trim();
  13. var email = document.getElementById("email").value.trim();
  14.  
  15. // 1. Check for empty fields
  16. if (name === "" || address === "" || bloodGroup === "" || dob === "" ||
  17. mobile === "" || aadhar === "" || email === "") {
  18. alert("All fields are required!");
  19. return false;
  20. }
  21.  
  22. // 2. Check Aadhar number length
  23. if (aadhar.length !== 12 || isNaN(aadhar)) {
  24. alert("Aadhar number must be exactly 12 digits and numeric!");
  25. return false;
  26. }
  27.  
  28. // 3. Check Age > 18
  29. var birthDate = new Date(dob);
  30. var today = new Date();
  31. var age = today.getFullYear() - birthDate.getFullYear();
  32. var monthDiff = today.getMonth() - birthDate.getMonth();
  33.  
  34. // Adjust age if birthday hasn't occurred this year
  35. if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {
  36. age--;
  37. }
  38.  
  39. if (age < 18) {
  40. alert("Applicant must be at least 18 years old!");
  41. return false;
  42. }
  43.  
  44. alert("Application submitted successfully!");
  45. return true;
  46. }
  47. </script>
  48. </head>
  49. <body>
  50. <h2>Driving Licence Application Form</h2>
  51. <form onsubmit="return validateForm()">
  52. Name: <input type="text" id="name"><br><br>
  53. Address: <textarea id="address" rows="3" cols="30"></textarea><br><br>
  54. Blood Group:
  55. <select id="bloodgroup">
  56. <option value="">Select</option>
  57. <option value="A+">A+</option>
  58. <option value="A-">A-</option>
  59. <option value="B+">B+</option>
  60. <option value="B-">B-</option>
  61. <option value="O+">O+</option>
  62. <option value="O-">O-</option>
  63. <option value="AB+">AB+</option>
  64. <option value="AB-">AB-</option>
  65. </select><br><br>
  66. Date of Birth: <input type="date" id="dob"><br><br>
  67. Mobile Number: <input type="text" id="mobile"><br><br>
  68. Aadhar Number: <input type="text" id="aadhar"><br><br>
  69. Email ID: <input type="text" id="email"><br><br>
  70.  
  71. <input type="submit" value="Submit">
  72. </form>
  73. </body>
  74. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement