1
2
3
4
5
6
7
8
9
10
11
/*
** 폼
**
** <input type="text" numberonly="true" />  // 숫자만 입력 가능한 텍스트박스
** <input type="text" datetimeonly="true" /> // 숫자, 콜론(:), 하이픈(-)만 입력 가능한 텍스트박스
*/
$(function()
{
 $(document).on("keyup""input:text[numberOnly]"function() {$(this).val( $(this).val().replace(/[^0-9]/gi,"") );});
 $(document).on("keyup""input:text[datetimeOnly]"function() {$(this).val( $(this).val().replace(/[^0-9:\-]/gi,"") );});
});


만약 on 메소드가 없는 존나 옛날 버전이라면


1
2
3
4
5
6
7
8
9
$(function()
{
    $("input:text[numberOnly]").live("keyup"function() {
        $(this).val( $(this).val().replace(/[^0-9]/gi,"") );
    });
    $("input:text[datetimeOnly]").live("keyup"function(){
        $(this).val( $(this).val().replace(/[^0-9:\-]/gi,"") );
    });
});

으로 해주면 된다. 


약간에 문제가 있는듯 합니다.

한글만 입력하고 focus가 나가면 한글 1글자가 남는.....


출처: http://hobbiez.tistory.com/396 [취미생활]

+ Recent posts