JavaScript

영문자, 숫자만 입력 가능
  • 조회수 4,011
  • 작성일 2012-08-22
  •  
function alpha_num_check(obj) {
  str = obj.value;
  len = str.length;
  ch = str.charAt(0);

  for(i = 0; i < len; i++) {
    ch = str.charAt(i);
    if( (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ) {
      continue; 
    } else {
      alert("영문과 숫자만 입력이 가능합니다.");
      obj.value="";
      obj.focus();
      return false;
    }
 }
 return true;
}
</script>

<input type="text" name="keypassword" maxlength="20" style="width:100px" onkeyup="alpha_num_check(this);">


  • Comment 2021-02-22 11:05
function checkNumber() {
var objEv = event.srcElement;
var numPattern = /([^0-9])/;
var numPattern = objEv.value.match(numPattern);
if (numPattern != null) {
//alert("숫자만 입력하세요");
objEv.value = "";
objEv.focus();
return false;
}
}