svk
svk

Reputation: 4553

how to make the Textbox to allow only three digits with three decimal points?

I want to make the textbox allow only three digits and three decimals.For example 999.999.similarly it doesnt allow any characters like a,b,/,etc.How can I do with the Jquery?

Upvotes: 2

Views: 2353

Answers (3)

barkmadley
barkmadley

Reputation: 5297

Have you looked at the jQuery.validate plugin?

$('#formid').validate({
    rules: {
        fieldname: {
            required:function(element) {
                return /^\s*[0-9]{,3}(?:\.[0-9]{1,3})?\s*$/.test(element.value);
            }
        }
    }
});

EDIT: admittedly I didn't test the regex and merely wanted to demonstrate how it works. Updated regex as per nickf's suggestion, thanks.

Upvotes: 1

Mottie
Mottie

Reputation: 86413

You could also look at this masked input plugin

Upvotes: 0

karim79
karim79

Reputation: 342635

Take a look at jQuery numeric plugin.

Upvotes: 1

Related Questions