반응형
<!DOCTYPE HTML>
<html>
<head>
<title>javascript 숫자 형식만 입력받기</title>
<style>
input {height:12px;}
p {display:inline;}
.nb {ime-mode: disabled;width:30px;}
</style>
<script type="text/javascript">
// 숫자 확인
String.prototype.only_number = function(){
return this.replace(/[^0-9]/gi, '');
}
</script>
</head>
<body>
<p>숫자 : </p>
<input type="text" id="n" maxlength="4" class="nb" value="" onblur="this.value=this.value.only_number();" />
</body>
</html>
반응형