2

I need validator that allow only characters,numbers, underscore and hypen. if user enter only spaces then disabled save button in angular 2 FormBuilder validators.pattern(). I already tried Validators.pattern(".*\\S.*") and Validators.pattern(".*\\S.*[a-zA-z0-9 ]") but not worked.

Pardeep Jain
  • 84,110
  • 37
  • 165
  • 215
Aniket Avhad
  • 4,025
  • 2
  • 23
  • 29

1 Answers1

0

Use like this

Validators.pattern(".*\\S.*[a-zA-z0-9_-]")

Working Demo

see also

Community
  • 1
  • 1
Pardeep Jain
  • 84,110
  • 37
  • 165
  • 215