正则表达式,不含空格或特殊字符[关闭]

I am new to regular expressions and I need a regex for php username that matches

no spaces

no special characters

in length 8, max 32

and also a regex for password that matches


alphanumeric have at least one digit and one character

no spaces

Try the following REGEX :

^\S+\w{8,32}\S{1,}
  • ^ means beginning of line
  • \S means all characters but not a space or a tab
  • + mean at least one character
  • \w means an alphanumeric character including _
  • {8,32} means at least 8 characters, and max 32
  • \S still means all characters but not a space or a tab
  • {1,} means at least 1 item