Sunday, May 19, 2013

Javascript Validation for Email

<script type='text/javascript'>
function emailValidator(elem, helperMsg){
    var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
    if(elem.value.match(emailExp)){
        return true;
    }else{
        alert(helperMsg);
        elem.focus();
        return false;
    }
}
</script>
<form>
Email: <input type='text' id='emailer'/>
<input type='button'
    onclick="emailValidator1(document.getElementById('emailer'), 'Not a Valid Email')"
    value='Check Field' />
</form>


No comments:

Post a Comment