node同时验证手机号和座机号
string strPatern2= @"(^(\d{3,4}-)?\d{6,8}$)"; string strPatern = @"(^1[3-8]\d{9}$|^\d{3}-\d{8}$|^\d{4}-\d{7}$)"; System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(strPatern); System.Text.RegularExpressions.Regex reg2 = new System.Text.RegularExpressions.Regex(strPatern2); if (reg.IsMatch(ConsigneeMobile) || reg2.IsMatch(ConsigneeMobile)) { } else { ErrorMsg += "电话格式不正确"; }
--------------------------------------------------------------------------------------
if (!row["收件人电话"]) { this.setMsg(`${i}、第${i + 1}收件人电话不能为空`, "red"); } else { let strPatern = /^1\d{10}$/gi; var re = new RegExp(strPatern); var strPatern2 = /^((0\d{2,3}-\d{7,8})|(1[3584]\d{9}))$/; var st = new RegExp(strPatern2); if (!re.test(consigneeMobile) && !st.test(consigneeMobile)) { // msg = `${i}、电话格式不正确`; // redis.rpush(body.key, msg); // this.info.result = false; this.setMsg(`${i}、第${i + 1}电话格式不正确`, "red"); } }
// 验证身份证号 18位和15位
let card = body.consignIdcard; var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; if (reg.test(card) === false) { this.info.result = false; this.info.msg = "身份证输入不合法!"; ctx.body = this.info; return; }