Regular expression in JavaScript to validate username size

3

I need a JavaScript regular expression that meets the following rules:

  • Have between 2 and 255 characters
  • In lower case
  • Only contain alphanumeric, underline (_), period (.) or hyphen (-).
asked by anonymous 11.01.2017 / 18:55

2 answers

3

Try this to capture exact line:

/^[a-z0-9_\.-]{2,255}$/

Meets the rules:

  • Have between 2 and 255 characters
  • In lower case
  • Contains only alphanumeric, unerline (_), period (.) or hyphen (-).
11.01.2017 / 18:59
1

The regex looks like this:

/^[a-z0-9_\.-]{2,255}$/
    
11.01.2017 / 18:56