1

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.

1 Answer 1

5

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
Sign up to request clarification or add additional context in comments.

4 Comments

\s will match tabs and newlines. Should use an explicit space.
Simple and efficient +1 :)
What's going on? Just sent my letter to Regex Santa in the chat room, might see you there? Off to feed the neighbor's cat for a mo.
Gotta love race conditions :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.