Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
ECMAScript (JavaScript)

/
^([\w\d]+)((?:([\s]{0,1}-[\s]{0,1}|\s)([\w\d])+){0,1})+$
/
gm

Description

This regular expression checks for below rules:

  • Must not have special characters except a dash sign
  • Must not start with a dash sign or white space
  • Must not end with a dash sign or white space
  • Must not have a dash sign or white space in sequence
Submitted by Vijay sasvadiya - 4 years ago