-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

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 に答える