I have a tex开发者_运维问答tbox and user enter a number in it. I want to allow 2 decimal digits.
For example; number: 12,256 -> I want to allow 12,25 not 3 digits after comma(2 number after comma). How can I do it?
Thanks, John
Use jQuery decimal mask plugin on your input field:
$("input").decimalMask({
separator: ".",
decSize: 2,
intSize: 8
});
Here is a plugin description
Yet one solution: jQuery: what is the best way to restrict “number”-only input for textboxes? (allow decimal points). In this case try to set up your regular expression.
Hope if helpful..
i would recommend using a user control that has two textboxes, one for the whole number part, one for the decimal part. it looks like an inelegant solution but if your software needs to work on clients with different regional settings, the standard thousand seperator and decimal seperator might cause a problem in the future. limiting the number of characters on the textbox with decimal part will solve your problem.
i would also recommend jquery for masked textbox formatting which is much more elegant than asp.net standard masked input controls.
http://digitalbush.com/projects/masked-input-plugin/
You can use MaskedEdit
from Ajax Control Toolkit
精彩评论