0
我需要在游戏中添加字母数字字段我试图将此代码如何添加字母数字字段中发挥框架
object TestValidation {
implicit val readTestUser: Reads[TestValidation] = (
(JsPath \ "firstName").read(minLength[String](1)) and
(JsPath \ "lastName").read(minLength[String](1)) and
(JsPath \ "email").read(email) and
(JsPath \ "password").read(minLength[String](1)))(TestValidation.apply _)
我想要的“密码”字段是字母数字 我已经加入此自定义的验证约束现在我想intregate此期间读取JSON的方法做这样的事情也许
(JsPath \ "password").read(minLength[String](1)).passwordCheckConstraint
我不知道正确的方式执行此操作, 被约束代码
val allNumbers = """\d*""".r
val allLetters = """[A-Za-z]*""".r
val passwordCheckConstraint: Constraint[String] = Constraint("constraints.passwordcheck")({
plainText =>
val errors = plainText match {
case allNumbers() => Seq(ValidationError("Password is all numbers"))
case allLetters() => Seq(ValidationError("Password is all letters"))
case _ => Nil
}
if (errors.isEmpty) {
Valid
} else {
Invalid(errors)
}
})
请帮助表示类型