Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想用这些参数验证用户名:“它只能包含字母数字字符或破折号,不能以破折号开头,长度必须在 2-20 个字符之间”
这是我的尝试,但不太正确
/^[a-z0-9]+([a-z0-9-]+[a-z0-9])?$/i
谢谢你的帮助
/^[a-z0-9][-a-z0-9]{1,19}$/i
[^-]允许各种非字母数字字符。
[^-]