我在grails上还很新,在使用正则表达式进行比赛验证时遇到了问题。我想发生的事情是我的字段可以接受字母数字和特定的特殊字符的组合,例如句点(.),逗号(,)和破折号(-),它可以接受数字(099)或仅接受字母(alpha),但是将不接受仅包含特殊字符(“.-,”)的输入。是否可以使用正则表达式过滤此类输入?
请帮忙。感谢您分享你的知识。
最佳答案
^[0-9a-zA-Z,.-]*?[0-9a-zA-Z]+?[0-9a-zA-Z,.-]*$
meaning:
/
^ beginning of the string
[...]*? 0 or more characters from this class (lazy matching)
[...]+? 1 or more characters from this class (lazy matching)
[...]* 0 or more characters from this class
$ end of the string
/
关于grails - 正则表达式验证-Grails约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9614508/