如何在scala play Framework FORMS中验证否定BigDecimals?

时间:2016-06-02 07:20:37

标签: scala validation playframework-2.0

我想在我的POST请求中验证(不允许)负数值 以下是我的验证特征,它具有表格映射,

bigDecimal具有精度和比例,但如何确保请求中出现负bigDecimals?

  trait BICValidation extends CommonValdidation {
      implicit val bICForm = Form(
        mapping(
          "id" -> optional(number),
          "name" -> text,
          "description" -> optional(text),
          "bId" -> optional(number),
          "amount" -> bigDecimal
        )(BIC.apply)(BIC.unapply)
      )
    }

1 个答案:

答案 0 :(得分:4)

尝试

"amount" -> bigDecimal.verifying("amount must be negative", a => a < 0)

并查看docs