繁体   English   中英

在JS中使用正则表达式进行字符串验证

[英]String validation with regex in JS

我需要帮助来构造正则表达式以验证Javascript中的字符串格式,

字符串的总长度应在3到30个字符之间。 第一个字符必须严格是字母。 后续字符可以是字母,点或空格。 请帮忙。

以下将为您工作。

var re = /^[a-z][a-z. ]{2,29}$/i

正则表达式:

^                # the beginning of the string
 [a-z]           # any character of: 'a' to 'z'
 [a-z. ]{2,29}   # any character of: 'a' to 'z', '.', ' ' (between 2 and 29 times)
$                # before an optional \n, and the end of the string

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM