javaScript Recex Проверка, если строка пуста
function IsEmptyOrWhiteSpace(str) {
return (str.match(/^\s*$/) || []).length > 0;
}
Zwazel
function IsEmptyOrWhiteSpace(str) {
return (str.match(/^\s*$/) || []).length > 0;
}
// Test whether strValue is empty or is None
if (strValue) {
//do something
}
// Test wheter strValue is empty, but not None
if (strValue === "") {
//do something
}
var myVar=null;
if(myVar === null){
//I am null;
}
if (typeof myVar === 'undefined'){
//myVar is undefined
}
if (!str.length) { ...
/**
* Checks the string if undefined, null, not typeof string, empty or space(s)
* @param {any} str string to be evaluated
* @returns {boolean} the evaluated result
*/
function isStringNullOrWhiteSpace(str) {
return str === undefined || str === null
|| typeof str !== 'string'
|| str.match(/^ *$/) !== null;
}
var string = "not empty";
if(string == ""){
console.log("Please Add");
}
else{
console.log("You can pass"); // console will log this msg because our string is not empty
}