0% found this document useful (0 votes)
8 views1 page

Emailandregex

Uploaded by

joshisakshi1204
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Emailandregex

Uploaded by

joshisakshi1204
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

<html >

<head>
<title>Validation Example</title>
<script>

function validateEmail(email) {
const emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
return emailRegex.test(email);
}

function validateAadhaar(aadhaarNumber) {
const aadhaarRegex = /^\d{12}$/;
return aadhaarRegex.test(aadhaarNumber);
}

function validateForm() {
const email = document.getElementById("email").value;
const aadhaar = document.getElementById("aadhaar").value;

if (validateEmail(email)) {
console.log("Email is valid.");
} else {
console.log("Email is invalid.");
alert("Please enter a valid email address.");
return false;
}

if (validateAadhaar(aadhaar)) {
console.log("Aadhaar number is valid.");
} else {
console.log("Aadhaar number is invalid.");
alert("Please enter a valid Aadhaar number (12 digits).");
return false; }

alert("Form submitted successfully!");


return true;
}
</script>
</head>
<body>

<h2>Form Validation</h2>
<form onsubmit="return validateForm()">
<label for="email">Email Address:</label>
<input type="text" id="email" name="email"><br><br>

<label for="aadhaar">Aadhaar Card Number:</label>


<input type="text" id="aadhaar" name="aadhaar"><br><br>

<button type="submit">Submit</button>
</form>

</body>
</html>

You might also like