[英]How to write Regular expression for minimum one character in javascript?
I have small requirement in Regular expression,here I need minimum of one letter of Alphabets and followed by numbers and special characters. 我在正则表达式中有一个小要求,这里我需要至少一个字母的字母,然后是数字和特殊字符。 I tried the following regular expressions but I'm not getting the solution. 我尝试了以下正则表达式,但我没有得到解决方案。
/^[a-zA-Z0-9\-\_\/\s,.]+$/
and 和
/^([a-zA-Z0-9]+)$/
I need minimum of one letter of Alphabets 我至少需要一个字母的字母
[a-z]+
and followed by numbers and special characters. 然后是数字和特殊字符。
[0-9_\/\s,.-]+
Combined together you would get this: 结合在一起你会得到这个:
/^[a-z]+[0-9_\/\s,.-]+$/i
The /i modifier is added for case insensitive matching of alphabetical characters. 添加了/ i修饰符,用于字母字符的不区分大小写匹配。
Try this regex: 试试这个正则表达式:
/^[a-z][\d_\s,.]+$/i
To clarify what this does: 澄清这是做什么的:
^[a-z] // must start with a letter (only one) add '+' for "at least one"
[\d_\s,.]+$ // followed by at least one number, underscore, space, comma or dot.
/i // case-insensitive
You need the other character selection to be separate. 您需要将其他字符选择分开。 I'm confused as to what "numbers and special characters" means, but try: 我对“数字和特殊字符”的含义感到困惑,但尝试:
/^[a-z]+[^a-z]+$/i
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.