﻿//### Check max length
function SetMaxLength(txt,maxLen){
    if (txt.value.length > (maxLen-1)){
        alert("This field is limited to " + maxLen + " characters.\n" + "You have reached the limit.")
        txt.focus()
        txt.value = txt.value.substring(0, maxLen)
    }
} 


//### Email validator
function emailValidator(elem){
    var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
    if(elem.value.length > 0){
        if(elem.value.match(emailExp)){
            return true;
        }else{
            alert('Not a valid email address');
            elem.focus();
            return false;
        }
    }
}  

