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.
如何使用正则表达式验证用户名?
对于我使用的英文字母、数字和空格:
/^[a-zA-Z]{1}([a-zA-Z0-9]|\s(?!\s)){4,14}[^\s]$/
如何添加阿拉伯字母?
好吧,这取决于您的角色是以 cp1256 还是 unicode 的形式出现的。如果是 unicode,您可以在表达式中使用 #([\x{0600}-\x{06FF}]+\s*) 等范围。
您将使用 unicode 正则表达式并匹配所有字母:
/\pL+/u
(一个或多个字母)