Monday 18 December 2017

javascript - JS how to check empty String and Space





Help me
pls



if(value == ""){
//
do
anything
}


but
I need to check space " " (2,3,... space is include) is the same way of empty
String




ps. sorry in my
English



Answer




A regex can easily solve this problem.



if (/^ *$/.test(value))
{
//string contains 0+ spaces
only
}


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...