Reputation: 2311
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.
Upvotes: 1
Views: 275
Reputation: 70732
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
Upvotes: 5