email match with confirm email address in contact form

Дтдця picture Дтдця · Aug 14, 2013 · Viewed 33k times · Source

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>

Answer

aizaz picture aizaz · Aug 14, 2013

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>