简体   繁体   中英

String validation with regex in JS

I need a help to frame a regex to validate a string format in Javascript,

Total length of the string should be between 3 and 30 characters length. First character must be strictly an alphabet. Subsequent characters can be either alphabet or dot or space. Please help.

The following will work for you.

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

Regular expression:

^                # 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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