Klapsius
Klapsius

Reputation: 3359

remove symbols from text field with jquery

I have function to remove symbols from a text. How to keep commas and dots ( . , ) in text field? Becouse at the moment function remove everithing who is not digits

$('.numbersOnly').bind("keyup paste", function(){
        setTimeout(jQuery.proxy(function() {
            this.val(this.val().replace(/[^0-9]/g, ''));
        }, $(this)), 0);

});

Upvotes: 1

Views: 90

Answers (3)

CASH
CASH

Reputation: 93

Change to:

$('.numbersOnly').bind("keyup paste", function(){
        setTimeout(jQuery.proxy(function() {
            this.val(this.val().replace(/[^0-9\.\,]/g, ''));
        }, $(this)), 0);

});

Upvotes: 1

Swaraj
Swaraj

Reputation: 383

Try this

this.val(this.val().replace(/[^0-9,.]/g, ''));

Upvotes: 2

Neel
Neel

Reputation: 11721

Try below code :-

$('.numbersOnly').bind("keyup paste", function(){
        setTimeout(jQuery.proxy(function() {
             this.val(this.val().replace(/[^0-9.,]/g, '')
        }, $(this)), 0);

});

Upvotes: 2

Related Questions