正则表达式以匹配没有连续空格的用户名 [英] regex to match a username with no consecutive spaces

查看:69
本文介绍了正则表达式以匹配没有连续空格的用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力使javascript正则表达式满足以下要求:

I am struggling to make a javascript regex to satisfy the following:

  1. 第一个字符必须为字母( [a-zA-Z] )
  2. 其余的可以是任何字母,任何数字,连字符,点,下划线和空格
  3. 但不能连续使用空格,,例如:连续两个或多个空格
  4. 长度必须在3到25(含)之间
  1. The first character has to be alphabetical ([a-zA-Z])
  2. The rest can be any letters, any numbers, hyphen, dot, underscore and spaces
  3. BUT no consecutive spaces, e.g: two or more spaces in a row
  4. 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

RegEx演示

这篇关于正则表达式以匹配没有连续空格的用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆