아는 것이 좋은 것이다.

[jQuery] 문자열 입력제한 본문

jQuery

[jQuery] 문자열 입력제한

start0 2014. 6. 27. 15:07
<!DOCTYPE>
<html>
<head>
<title> 문자열 입력 제한 </title>
</head>
<body>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>

<input type="text" name="number" id="number"/>
<input type="text" name="datetime" id="datetime"/>
<input type="text" name="eng" id="eng"/>
<script type="text/javascript">
$(document).ready(function() {
$("#number").keyup(function(){ $(this).val($(this).val().replace(/[^0-9]/gi,"") );  }); //숫자만
$("#datetime").keyup(function(){ $(this).val($(this).val().replace(/[^0-9:\-]/gi,"") );  }); //숫자 및 하이폰(-)
$("#eng").keyup(function(){ $(this).val($(this).val().replace(/[^a-z0-9:\-_]/gi,'') );  }); //숫자, 하이폰(-), 영문, 언더바(_),한글(X)
});

</script>
</body>
</html>

Comments