Javascript String isBlank(pattern)

Description

Javascript String isBlank(pattern)


/**//  w  w  w .ja  v  a 2 s . c o m
 *  String#isBlank() -> Boolean
 *
 *  Check if the string is "blank" — either empty (length of `0`) or
 *  containing only whitespace.
 *
 *  ##### Example
 *
 *      ''.isBlank();
 *      //-> true
 *
 *      '  '.isBlank();
 *      //-> true
 *
 *      ' a '.isBlank();
 *      //-> false
**/
String.prototype.isBlank = function(pattern) {
  return /^\s*$/.test(this);
};



PreviousNext

Related