Determine whether the string is empty
var strings = ''; if (string.length == 0) { alert('can't be empty'); }Determine whether the string is an "empty" character, that is, the user has entered a space
var strings = ' '; if (strings.replace(/(^s*)|(s*$)/g, "").length ==0) { alert('can't be empty'); }Determine whether the input string is empty or all are spaces
function isNull( str ){if ( str == "" ) return true;var regu = "^[ ]+$";var re = new RegExp(regu);return re.test(str);}If there is null, the above code cannot be judged normally. The following code is the case when null is judged as null.
var exp = null; if (exp == null) { alert("is null"); }When exp is undefined, the same result as null is also obtained, although null and undefined are different.
Note: This method can be used when judging null and undefined at the same time. The code is as follows
var exp = null; if (!exp) { alert("is null"); }If exp is undefined, or the number zero, or false, you will also get the same result as null, although null is different from the two. Note: This method can be used when judging null, undefined, numeric zero, and false at the same time. The code is as follows
var exp = null; if (typeof exp == "null") { alert("is null"); }For backward compatibility, when exp is null, typeof null always returns object, so this cannot be judged.
<script type="text/javascript">function testuser(){var i= document.getElementByIdx_x("aa");if (i.value=="null"){alert("Please log in before leaving a message!")return false;}else{alert(i.value)return true;}}</script>The above method of determining whether the input string is empty, space, or null is the entire content shared by the editor. I hope it can give you a reference and I hope you can support Wulin.com more.