W
W
WhatIsHTML2018-08-08 01:39:58
Angular
WhatIsHTML, 2018-08-08 01:39:58

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

2 answer(s)
0
0xD34F, 2018-08-08
@WhatIsHTML

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

Then try this [pattern]="'.*\\S.*'":

V
Vladimir Proskurin, 2018-08-08
@Vlad_IT

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 question

Ask a Question

731 491 924 answers to any question