正则表达式验证 - grails
我对 grails 还很陌生。我现在在使用匹配进行验证时遇到了一些问题。我想要发生的是,一个字段可以接受字母数字和特殊字符的组合,仅字母和数字,并且如果用户仅输入特殊字符,系统应提示用户错误。 我使用匹配约束来验证数据,但我很难设置正则表达式,使该字段不接受仅包含特殊字符的输入。 请帮助我..非常感谢您分享您的知识。
im pretty new in grails.. im having a little problem right now on validation using matches. What I wanted to happen is that a field can accept combination of alphanumeric and special characters, letters only and numbers only, and if the user inputs special characters only, the system should prompt the user an error.
i used matches constraints to validate the data, and im having a hard time how could i set the regex where the field will not accept an input with special characters only.
please help me.. thanks a lot for sharing your knowledge.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想我理解你的问题,但如果我错了,请纠正我。只要输入至少 1 个字母或数字就有效,对吗?换句话说,如果没有字母或数字(只有特殊字符),那么输入无效?
看看这是否有效:
这是我的小测试:
解释:
I think I understand your problem, but correct me if I'm wrong. The input is valid as long as there is at least 1 letter or number, right? In other words, if there isn't a letter or number (only special characters), then the input is invalid?
See if this works:
Here is my little groovy test:
Explained:
我不知道 grails 是否支持 lookaround,但如果支持,这个正则表达式将起作用为您:
说明:
I don't know if grails supports lookaround, but if it does, this regex will work for you:
explanation: