开发者

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

开发者 https://www.devze.com 2022-12-10 11:42 出处:网络
I want to make the text开发者_运维知识库box 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?Have you

I want to make the text开发者_运维知识库box 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?


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.


Take a look at jQuery numeric plugin.


You could also look at this masked input plugin

0

精彩评论

暂无评论...
验证码 换一张
取 消