Javascript String whitespace()

Description

Javascript String whitespace()


/*//from  w w w. j a  v a2s  .c om
 * Implement String.whitespace? which should return true if given 
 object consists of exclusively zero or more whitespace characters, false otherwise
 */
"use strict";
String.prototype.whitespace=function(){
    return this.replace(/\n|\r|\t|\s/g, "").length == 0;
}

Javascript String whitespace()

//hmm.. guess this works? 
String.prototype.whitespace = function() {
  return /^\s*$/.test(this);
};



PreviousNext

Related