Combine two regular expression into one while validating Attribute

假如想象 提交于 2019-12-02 07:05:09

You may use

^[^~!@#$%&*]*[^~!@#$%&*\s][^~!@#$%&*]*$

See the regex demo

Details

  • ^ - start of string
  • [^~!@#$%&*]* - 0+ chars other than a char in the ~!@#$%&* list
  • [^~!@#$%&*\s] - a char other than a char in the ~!@#$%&* list and whitespace
  • [^~!@#$%&*]* - 0+ chars other than a char in the ~!@#$%&* list
  • $ - end of string.

NOTE: To also allow an empty string you need to wrap the pattern between the anchors within an optional group: ^(?:[^~!@#$%&*]*[^~!@#$%&*\s][^~!@#$%&*]*)?$.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!