Regex for numbers and specific special characters -


I am using this regex for specific sets of special characters and specific sets.

  [0-9] + [\ (\) - / #] *) $  

This does not restrict special characters as specified is.

Make sure that the initial anchor Use ^ and avoid unnecessary to avoid inside the character class:

  ^ ([0-9] + [() / # -] * ) $  
  • Anchors will avoid problems starting / ending matching unwanted inputs.
  • Also keep in mind that the hyphen avoids avoiding if this character is placed in the first or last position within the class

Comments