regex is not empty string code example
Example 1: regex to check non empty string
/^(?!\s*$).+/
Example 2: regex empty string
const REGEXP = /^$/;
const validate = (text) => {
return REGEXP.test(text);
}
const isEmpty = validate("");
const isNotEmpty = validate("x");
console.log(isEmpty);
console.log(isNotEmpty);
Example 3: regex is not empty string
const REGEXP = /^$/;
const validate = (text) => {
return REGEXP.test(text);
}
const isNotEmpty = validate("x");
const isEmpty = validate("");
console.log(isNotEmpty);
console.log(isEmpty);