The validation package allows you to create ad-hoc constraints using the verifying method. However, Play gives you the option of creating your own custom constraints, using the Constraint case class.

Here, we’ll implement a simple password strength constraint that uses regular expressions to check the password is not all letters or all numbers. A Constraint takes a function which returns a ValidationResult, and we use that function to return the results of the password check:

Found an error in this documentation? The source code for this page can be found here. After reading the documentation guidelines, please feel free to contribute a pull request. Have questions or advice to share? Go to our community forums to start a conversation with the community.