Use
String.prototype.isEmpty = function() { if (!this.match(/\S/)) { return ('enter some valid input.Empty space is not allowed'); } else { return "correct input"; } } alert("test 1:"+(" ".isEmpty())); alert("test 2:"+(" \t ".isEmpty())); alert("test 3:"+(" \n ".isEmpty())); alert("test 4:"+("hi".isEmpty()));
Note:
\ s will match whitespace: space, tab or newline.
\ S will match a character without spaces: nothing but a space, tab, or newline. If your line has one character, which is not space, tab or new line, then it is not empty. So you just need to look for one character: \ S
sweets-blingbling
source share