Monday, October 14, 2013

How To Make Email Match With Confirm Email

This code will verify email match with confirm Email


<div>
<label for="email">email</label><input type='email' id='p1'><br /><br />
<label for="email">Confirm email</label><input type='email'
onfocus="validateMail(document.getElementById('p1'), this);"
oninput="validateMail(document.getElementById('p1'), this);">
</div>

<script type="text/javascript">
function validateMail(p1, p2) {
if (p1.value != p2.value || p1.value == '' || p2.value == '') {
p2.setCustomValidity('email incorrect');
} else {
p2.setCustomValidity('');
}
}
</script>


Here Another Way


form
<form action="contact.php" method="post" name="form1" id="form1">
<input name="email" type="text" required="1" id="email"/>
<input name="emailConfirm" type="text" id="confemail" onblur="confirmEmail()"/>
</form>

JS

<script type="text/javascript">
function confirmEmail() {
var email = document.getElementById("email").value
var confemail = document.getElementById("confemail").value
if(email != confemail) {
alert('Email Not Matching!');
}
}
</script>


How To Make Email Match With Confirm Email

No comments:

Post a Comment