我是 Play 2.3.x 和 Scala 的新手,并试图实现表单输入验证。
假设我有一个示例表格。
val userForm = Form(
"firstName" -> nonEmptyText
)
我想为名字字段实现类似的东西:
If a regex for first name (say firstName.regex = “regex for first name” ) is defined then {
Validate first name against specific regex
}else{
Validate against the global regex ( say global.regex = “global regex white list some regex valid for across the application”)
}
另外,我想将此与多个(链接/逐步)验证结合起来,以便能够显示:
- 如果未输入任何内容 - 请输入名字
- 如果名字已输入且未通过正则表达式验证 - 请输入有效的名字
我想开发一个通用解决方案,以便我可以将它用于所有领域。
感谢任何帮助。