Дтдця
Дтдця

Reputation: 354

email match with confirm email address in contact form

I would like to match a user's email address with the confirmed email address. I have tried HTML5 validation but it's not working and I don't know why. I would like to use jQuery in my contact form to match.

<form action="contact.php" method="post" name="form1" id="form1">
    <input name="email" type="text" required="1" id="email" size="44" />
    <input name="emailConfirm" type="text"  size="44" class="required email" equalTo='#email'  equals="email" err="Confirm email must be the same as email"   />
</form>

Upvotes: 3

Views: 41234

Answers (2)

Pandiyan Cool
Pandiyan Cool

Reputation: 6575

Try out this

<div class="required">
  <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>

Javascript

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

Upvotes: 2

aizaz
aizaz

Reputation: 3062

Use javascript

<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>

Upvotes: 15

Related Questions