简体   繁体   English

正则表达式:允许字母,数字和空格(至少有一个字母不是数字)

[英]Regular Expression: Allow letters, numbers, and spaces (with at least one letter not 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. 我正在使用这个正则表达式( /^[A-Za-z0-9 _]*[A-Za-z0-9][A-Za-z0-9 _]*$/ )接受字母,数字,空格和下划线。 I want to change it like this that it takes the combination of number and the character but not only the number. 我想改变它,它需要数字和字符的组合,而不仅仅是数字。

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 . 试试这个: /^(?:[A-Za-z]+)(?:[A-Za-z0-9 _]*)$/在这个在线正则表达式测试仪上

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). 这允许每个外部组中的0个或更多个,以及内部组中的一个或多个(仅字母)。 A string of only digits will fail. 只有一串数字才会失败。

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 使用regexr查看它的实际操作

/^[\w\s]+$/

\\w allows letters, numbers and underscores \\ w允许字母,数字和下划线

\\s allow spaces \\ s允许空格

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 正则表达式:允许字母,数字和空格(至少包含一个字母或数字) - Regular Expression: Allow letters, numbers, and spaces (with at least one letter or number) javascript:使用RegEx允许字母,数字和空格(至少包含一个字母和数字) - javascript: Use RegEx to allow letters, numbers, and spaces (with at least one letter and number) 正则表达式强制在字符串中至少包含一个字母和数字? - regular expression to force to have at least one letter and number in a string? 正则表达式:仅限字母、数字、空格、连字符、句点和下划线,并且必须以字母开头 - Regular Expression: Letters, numbers, spaces, hyphens, periods, and underscores only and must begin with a letter 正则表达式至少匹配一个大写字母和至少一个数字和任意数量的特殊字符 - Regular expression to match at least One capital letter and at least One digit and any number of special charecter 至少一个数的正则表达式 - Regular Expression For At Least One Number 需要 4-12 个字母数字字符或特殊字符 (~!@$%&*_+) 至少一个字母的正则表达式,不能有空格 - Need regular expression for 4-12 alphanumeric characters or special characters (~!@$%&*_+) at least one letter, no spaces Javascript正则表达式,表示“至少X个字符,带有大写字母和数字” - Javascript regular expression for “at least X characters, have a capital letter and a number” 密码的正则表达式至少包含 2 个大写字母、2 个小写字母、2 个符号和 2 个任意顺序的数字 - Regular expression for a password containing at least 2 uppercase letters, 2 lowercase letters, 2 symbols, and 2 numbers in any sequence 具有一个连字符(1-5)的数字和具有单个空格的数字(1 2 3 4 5)的正则表达式 - Regular expression for numbers with one hyphen(1-5) and numbers with single spaces (1 2 3 4 5)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM