马宇豪
2023-03-30 43fca2cb16964496caafdbc34e969d2a7cde7cc0
src/utils/toolsValidate.ts
@@ -366,3 +366,55 @@
    // true:车牌号正确
    else return true;
}
export function checkChineseName (name:string) {
    let reg = /^[\u4e00-\u9fa5]{2,15}$/;
    // 保留点后,用来校验的姓名,也是最终校验通过后返回的姓名
    let payerName = name.replaceAll(" ", "")
        .replaceAll(" ", "")
        .replaceAll("•", "·")
        .replaceAll(".", "·");
    // 去除所有点后,用来校验的姓名
    let checkName = name.replaceAll(" ", "")
        .replaceAll(" ", "")
        .replaceAll("•", "")
        .replaceAll(".", "")
        .replaceAll("·", "");
    if(checkName.length === 1){
        // this.$message({
        //   type:'warning',
        //   message:'姓名至少包含两位汉字'
        // })
        return false;
    }
    if (reg.test(checkName)) {
        if(payerName.substring(0,1) === '·'){
            // this.$message({
            //   type:'warning',
            //   message:'姓名第一位不能为“·”'
            // })
            return false;
        }
        if(payerName.substring(payerName.length - 1) === '·'){
            // this.$message({
            //   type:'warning',
            //   message:'姓名最后不能为“·”'
            // })
            return false;
        }
        if(payerName.indexOf("··") !== -1){
            // this.$message({
            //   type:'warning',
            //   message:'姓名不能有连续的“·”'
            // })
            return false;
        }
        return payerName;
    } else {
        // this.$message({
        //   type:'warning',
        //   message:'姓名中只能包含汉字和“·”'
        // })
        return false;
    }
}