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)
}
})
請幫助表示類型