숫자, 이메일, 길이 검증

1865 단어 html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<script type="text/javascript">
validateNumber = function(id) {
    var input = document.getElementById(id); 
    input.onkeypress = function() {
   return event.keyCode >= 48 && event.keyCode <= 57
       || event.keyCode == 45 || event.keyCode == 43;
    }
    input.onbeforepaste = function() {
       clipboardData.setData('text', clipboardData.getData('text').replace(
       /[^-+\d]/g, ''));
    }
    input.style.imeMode = "disabled";
}

validateEmail = function(id){
    var input = document.getElementById(id); 
    var emailRegex = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
    var emailRegex2 = /^(?:\w+.?)*\w+@(?:\w+\.?)+\w+$/;
    if(!emailRegex.test(input.value)){
       alert("Email !");
     input.value="";
    }
}

validateLength = function(id,len){
    var input = document.getElementById(id);
    if(input.value.length<len)
    alert(" "+len+" ");
}
</script>
</HEAD>

<BODY>
<br><a> :</a>
<input id="number" value="" onclick="validateNumber('number')">
<br>
<br><a>Email :</a>
<input id="email" value="" onblur="validateEmail('email')">
<br>
<br><a> :</a>
<input type="password" id="length" value="" onblur="validateLength('length',6)">
</BODY>
</HTML>

좋은 웹페이지 즐겨찾기