JSP·script·jquery

css 와 jquery 를 이용한 text 숫자 제한 소수점 입력 포함

초이짬 2014. 3. 7. 12:01
728x90

$(document).ready(function() {
//정수만
$('.num_only').css('imeMode','disabled').keypress(function(event) {
if(event.which && ( event.which < 48 || event.which > 57) ) {
event.preventDefault();
}
}).keyup(function(){
if( $(this).val() != null && $(this).val() != '' ) {
$(this).val( $(this).val().replace(/[^0-9]/g, '') );
}
});

//금액
$('.num_only2').css('imeMode','disabled').keypress(function(event) {
if(event.which && (event.which < 48 || event.which > 57) ) {
event.preventDefault();
}
}).keyup(function(){
if( $(this).val() != null && $(this).val() != '' ) {
//var tmps = $(this).val().replace(/[^0-9]/g, '');
var tmps = $(this).val().replace(/[^0-9]/g, '');
var tmps2 = tmps.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
$(this).val(tmps2);
}
});
//소수점포함
$('.num_only3').css('imeMode','disabled').keypress(function(event) {
if(event.which && ( event.which < 45 || event.which > 57) ) {
event.preventDefault();
}
}).keyup(function(){
if( $(this).val() != null && $(this).val() != '' ) {
$(this).val( $(this).val().replace(/[^\.0-9]/g, '') );
}
});
});

728x90