我在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 
  / 


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!