开发者

What regular expression will match decimal values restricted to 6 decimal positions?

I have to write a regular expression that will match the following patterns, it should match decimal values, which can be in the formats shown below.

  1. +100.00
  2. -100.00
  3. .6777
  4. 0.45555
  5. the normal entry of the decimal values like 100 100.25 100.... and also the decimal points should be restricted 6 decimal positions.

This is the regular expression I have written so far:

return Regex.IsMatch(value, "^((\\+|-)(\\d*))+((\\.|,)\\d{0,5})?$");

Currently if the value is like +100 or -100 the reqular expression matches. If I enter a 开发者_开发百科value like 100, it is not accepted and if I start with the a decimal point like .899 then IsMatch returns false.


The correct expression is

^((\+|-)?(\d*))+((\.|,)\d{0,6})?$

You can test it at http://www.fileformat.info/tool/regex.htm.


You can try with:

^[+-]?\d*([.,]\d{1,6})?$


(+|-)?\d*[.,]?\d{0,6}$ and 7 gnomes to be posted.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜