0

Currently I have a function that checks if a string is empty or not, but it does not detects if I there is a new line

export const isStrEmpty = function(text: string): boolean {
  return !text || text.match(/^ *$/) !== null;
};

I tried adding \n, it doesn't work

export const isStrEmpty = function(text: string): boolean {
  return !text || text.match(/^ *\n$/) !== null;
};

Is there a way I can make this function detects if there is a new line in the string?

Alan S
  • 93
  • 1
  • 9

2 Answers2

0

If you want to do it the regex way:

^\s*$

where \s* matches any whitespace character (equal to [\r \n \t \f \v])

A similar Question was asked here: How to check if a line is blank using regex

true_gler
  • 544
  • 6
  • 23
0
return letter.trim()==='' ? true : false;

Please try this.

Divyesh patel
  • 967
  • 1
  • 6
  • 21