3
I need a regular Javascript expression that meets the following rules:
- Between 2 and 255 characters
- In low box (Lower case)
- Contain only alphanumerics, underline (_), dot (.) or hyphen (-).
3
I need a regular Javascript expression that meets the following rules:
3
Try this to capture exact line:
/^[a-z0-9_\.-]{2,255}$/
Play by the rules:
1
The regex looks like this:
/^[a-z0-9_\.-]{2,255}$/
William, two small corrections: the character -(dash) should be at the end of the list, otherwise it will be interpreted as an interval, similar to a-z. And if I’m not mistaken there’s no need to escape .(dot) inside the brackets[].
Good! I did it in my head. You’re right, corrected.
Must escape the point.
Special characters (such as the dot (.
) and the asterisk(*
)) it has no meaning when it is within a character set. It does not need to use escape in them. But using exhaust will also work. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#special-Character-set
Browser other questions tagged javascript regex
You are not signed in. Login or sign up in order to post.
tip, this site is very good for testing your regex and tbm lets you save and share them. http://www.regexpal.com/
– Renato Colaço
Need to allow accented characters?
– bfavaretto