-1

正则表达式模式可以对数值强制执行以下约束组合吗?

     the number must be >= 1 and <= 999 
     (decimal point cannot be the first character in the string?)

     the number can be an integer or a number with a fractional component

     when it has a fractional component, 
     no more than 2 digits to the right of the decimal point 
     EDIT: but at least one digit to the right

     must not have leading zero(s)
4

3 回答 3

1

Perl 语法:

^+?(?:(?:999(?:\.0{1,2})?)|(?:(?!999)[1-9]\d{0,2}(?:\.\d{1,2})?))$
于 2013-09-20T09:05:51.293 回答
0

是的..

^(?!999[.](0*[1-9]+$))(?!0|[.])\d{1,3}([.]\d{1,2})?$
于 2013-09-20T09:01:10.483 回答
0

我会选择这个:

/^
(?:
  999.0*                      # 999.000
  |                           # or
  [1-9]\d{,2}((?<!999)\.\d+)? # 1-998 plus optional .\d*
)
$/x
于 2013-09-20T10:16:52.790 回答