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.
Asked
Active
Viewed 3,922 times
2

Pardeep Jain
- 84,110
- 37
- 165
- 215

Aniket Avhad
- 4,025
- 2
- 23
- 29
1 Answers
0
Use like this
Validators.pattern(".*\\S.*[a-zA-z0-9_-]")
see also

Community
- 1
- 1

Pardeep Jain
- 84,110
- 37
- 165
- 215
-
as per working demo if we enter combination of special character and alphabets then its not working properly. – Aniket Avhad Mar 25 '17 at 09:52
-
for eg. if enter abc%k like this then its not working. – Aniket Avhad Mar 25 '17 at 10:03
-
opps i did't see special symbol in your question, btw good question – Pardeep Jain Mar 25 '17 at 10:07