Skip to content

Instantly share code, notes, and snippets.

@basilboli
Created May 13, 2019 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save basilboli/52a1aa04daf3355367a9c73bd60c1a4f to your computer and use it in GitHub Desktop.
Save basilboli/52a1aa04daf3355367a9c73bd60c1a4f to your computer and use it in GitHub Desktop.
package io.xendera.framework.server.constraints
import play.api.data.{Forms, Mapping}
import play.api.data.validation.{Constraint, Invalid, Valid, ValidationError}
object FormConstraints {
private val PasswordConstraint = "constraint.xendera.password"
private val MinLengthMessage = PasswordConstraint + ".error.minLength"
private val MinLength = 8
private def passwordConstraint: Constraint[String] =
Constraint[String](PasswordConstraint) { v =>
if (v != null && v.length >= MinLength) Valid else Invalid(ValidationError(MinLengthMessage, MinLength))
}
val password: Mapping[String] = Forms.text.verifying(passwordConstraint)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment