该框应允许:
- 大小写字母(不区分大小写)
- 数字 0 到 9
- Angular 色,! # $ % & ' * + -/= ? ^ _ ` { | } ~
- 字符“.”前提是它不是第一个或最后一个字符
最佳答案
尝试
^(?!\.)(?!.*\.$)[\w.!#$%&'*+\/=?^`{|}~-]*$
说明:
^ # Anchor the match at the start of the string
(?!\.) # Assert that the first characters isn't a dot
(?!.*\.$) # Assert that the last characters isn't a dot
[\w.!#$%&'*+\/=?^`{|}~-]* # Match any number of allowed characters
$ # Anchor the match at the end of the string
关于javascript - 需要有关 Javascript 正则表达式的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4848623/