admin 管理员组

文章数量: 1184232

I'm currently using this regex (/^[A-Za-z0-9 _]*[A-Za-z0-9][A-Za-z0-9 _]*$/) to accept letters, numbers, spaces and underscores. I want to change it like this that it takes the combination of number and the character but not only the number.

I'm currently using this regex (/^[A-Za-z0-9 _]*[A-Za-z0-9][A-Za-z0-9 _]*$/) to accept letters, numbers, spaces and underscores. I want to change it like this that it takes the combination of number and the character but not only the number.

Share Improve this question edited Sep 22, 2014 at 9:28 Scimonster 33.4k10 gold badges79 silver badges91 bronze badges asked Sep 22, 2014 at 9:19 Vishal SinghVishal Singh 6281 gold badge7 silver badges25 bronze badges 1
  • 1 try this /^[A-Za-z0-9 _]*[A-Za-z]+[A-Za-z0-9 _]*$/ – Aleksandar Gajic Commented Sep 22, 2014 at 9:28
Add a comment  | 

4 Answers 4

Reset to default 8

If i understand correctly you want to allow a string that begins with at least one letter and optionally is followed by number or underscore or space.

Try this: /^(?:[A-Za-z]+)(?:[A-Za-z0-9 _]*)$/ at this online regex tester.

This should work.

Cheers!

Try this:

/^[A-Za-z0-9 _]*[A-Za-z]+[A-Za-z0-9 _]*$/

This allows for 0 or more of each of the outside groups, and 1 or more of the inner group (letters only). A string of only digits will fail.

/^[\w\s]+$/

\w allows letters, numbers and underscores

\s allow spaces

Try this:
^(?![0-9]*$)[a-zA-Z0-9\s_]+$

This expression has a negative lookahead to verify that the string is not only numbers. See it in action with regexr

本文标签:

Error[2]: Invalid argument supplied for foreach(), File: /www/wwwroot/roclinux.cn/tmp/view_template_quzhiwa_htm_read.htm, Line: 58
File: /www/wwwroot/roclinux.cn/tmp/route_read.php, Line: 205, include(/www/wwwroot/roclinux.cn/tmp/view_template_quzhiwa_htm_read.htm)
File: /www/wwwroot/roclinux.cn/tmp/index.inc.php, Line: 129, include(/www/wwwroot/roclinux.cn/tmp/route_read.php)
File: /www/wwwroot/roclinux.cn/index.php, Line: 29, include(/www/wwwroot/roclinux.cn/tmp/index.inc.php)