Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Driving Licence Application</title>
- <script>
- function validateForm() {
- var name = document.getElementById("name").value.trim();
- var address = document.getElementById("address").value.trim();
- var bloodGroup = document.getElementById("bloodgroup").value;
- var dob = document.getElementById("dob").value;
- var mobile = document.getElementById("mobile").value.trim();
- var aadhar = document.getElementById("aadhar").value.trim();
- var email = document.getElementById("email").value.trim();
- // 1. Check for empty fields
- if (name === "" || address === "" || bloodGroup === "" || dob === "" ||
- mobile === "" || aadhar === "" || email === "") {
- alert("All fields are required!");
- return false;
- }
- // 2. Check Aadhar number length
- if (aadhar.length !== 12 || isNaN(aadhar)) {
- alert("Aadhar number must be exactly 12 digits and numeric!");
- return false;
- }
- // 3. Check Age > 18
- var birthDate = new Date(dob);
- var today = new Date();
- var age = today.getFullYear() - birthDate.getFullYear();
- var monthDiff = today.getMonth() - birthDate.getMonth();
- // Adjust age if birthday hasn't occurred this year
- if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {
- age--;
- }
- if (age < 18) {
- alert("Applicant must be at least 18 years old!");
- return false;
- }
- alert("Application submitted successfully!");
- return true;
- }
- </script>
- </head>
- <body>
- <h2>Driving Licence Application Form</h2>
- <form onsubmit="return validateForm()">
- Name: <input type="text" id="name"><br><br>
- Address: <textarea id="address" rows="3" cols="30"></textarea><br><br>
- Blood Group:
- <select id="bloodgroup">
- <option value="">Select</option>
- <option value="A+">A+</option>
- <option value="A-">A-</option>
- <option value="B+">B+</option>
- <option value="B-">B-</option>
- <option value="O+">O+</option>
- <option value="O-">O-</option>
- <option value="AB+">AB+</option>
- <option value="AB-">AB-</option>
- </select><br><br>
- Date of Birth: <input type="date" id="dob"><br><br>
- Mobile Number: <input type="text" id="mobile"><br><br>
- Aadhar Number: <input type="text" id="aadhar"><br><br>
- Email ID: <input type="text" id="email"><br><br>
- <input type="submit" value="Submit">
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement