开发者

Validate values for decimal and integers

I need to validate that a TextBox contains only numbers, with allowances for commas and/or decimal points.

Here are a few examples of valid entries:

  • 12.7
  • 19.245,7
  • 11,123.326.7
  • 16,7
  • 0.19
  • 0,5

And here are some examples of invalid entries:

  • 12.00 --> 12
  • 19.000,7 --> 19000,7
  • .125 --> 0.125
  • 000.000 --> 0

I'm using thi开发者_StackOverflow中文版s regex, both it doesn't work: @"^[0-9]([\.\,][0-9]{1,3})?$"

How can I do this?


If you are using asp.net. You can use the comparevalidator and set the Operator to DataTypeCheck and set Type to Double (or currency)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜