Know how to check empty string in JavaScript. Many developers uses ==”” to check this but this may be fail in some scenario like string with space or with new line or carriage return characters. To do this here is one regular expression based JavaScript function to check empty string safely.
<script type="text/javascript"> function makeString(object) { if (object == null) return \'\'; return String(object); }; function isBlank(str) { return (/^s*$/).test(makeString(str)); }; //test function document.write(\'<p> blank test \'+isBlank("") +\'</p>\'); document.write(\'<p> blank test \'+isBlank(" ")+\'</p>\'); document.write(\'<p> blank test \'+isBlank("r")+\'</p>\'); document.write(\'<p> blank test \'+isBlank("n")+\'</p>\'); document.write(\'<p> blank test \'+isBlank("/")+\'</p>\'); </script>
You can uses above function to do this in safe manner.
Here is output of above code.