js 经常使用工具函数

/**
 * 校验字符串是否含有特殊字符
 * @param {String} newName 
 * @returns {Boolean} false | true 返回一个布尔值
 */
export const hasSpecialChar= function(newName){
    let regEn = /[`~!@#$%^&*()_+<>?:"{},.\/;'[\]]/im,
        regCn = /[·!#¥(——):;“”‘、,|《。》?、【】[\]]/im;
        
    if(regEn.test(newName) || regCn.test(newName)) {
        return true;
    }else {
        return false;
    }
}
/**
 * 校验字符串是否为空【null undefined ''】三种状况
 * @param {String} str 
 * @returns {Boolean} false | true 返回一个布尔值
 */
export const isEmpty = function (str){
    if(str === null || str === undefined || str === ""){
        return true
    }else {
        return false
    }
}
相关文章
相关标签/搜索