Answer the question
In order to leave comments, you need to log in
JS regex condition: string consists of more than just spaces?
Help me write a regular expression. The string can contain spaces, but cannot be all spaces. Those.
' ' // false
'some text' // true
Answer the question
In order to leave comments, you need to log in
Why use regular expressions here? Everything is much simpler !!str.trim()
:.
However, the regular expression is also not very complicated: /[^\s]/.test(str)
.
UPD. Taken from the comments:
the idea was to put a regular expression in the angular form validation pattern
[pattern]="'.*\\S.*'"
:
Why not call trim, and if the string is empty, then it was from spaces or empty (you can do an additional check for an empty string before trim).
Regulars need to be used in special cases.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question