正则表达式以匹配没有连续空格的用户名 [英] regex to match a username with no consecutive spaces
本文介绍了正则表达式以匹配没有连续空格的用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在努力使javascript正则表达式满足以下要求:
I am struggling to make a javascript regex to satisfy the following:
- 第一个字符必须为字母(
[a-zA-Z]
) - 其余的可以是任何字母,任何数字,连字符,点,下划线和空格
- 但不能连续使用空格,,例如:连续两个或多个空格
- 长度必须在3到25(含)之间
- The first character has to be alphabetical (
[a-zA-Z]
) - The rest can be any letters, any numbers, hyphen, dot, underscore and spaces
- BUT no consecutive spaces, e.g: two or more spaces in a row
- The length has to be between 3 and 25 (inclusive)
这就是我发现的正则表达式:
/^[a-z][\s\w.-]{3,24}$/i
我当前的正则表达式可以运行,但是无法测试用户是否已写出连续的空格.我该如何测试?
My current regex works, but won't be able to test whether the user has written consecutive spaces. How can I test for that?
推荐答案
这应该对您有用:
/^[a-z](?!.* {2})[ \w.-]{2,24}$/gmi
这篇关于正则表达式以匹配没有连续空格的用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文