John
John

Reputation: 386

Number Decimal Format

I have a textbox 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

Upvotes: 1

Views: 2343

Answers (3)

mastak
mastak

Reputation: 1467

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..

Upvotes: 2

Rafal Spacjer
Rafal Spacjer

Reputation: 4918

You can use MaskedEdit from Ajax Control Toolkit

Upvotes: 0

Cihan Kurt
Cihan Kurt

Reputation: 153

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/

Upvotes: 1

Related Questions