数据分析师2017-10-01 00:52:55
jQuery uses regular expressions to verify mobile phone numbers, ID numbers, and how to write Chinese names? -PHP Chinese website Q&A-How to use jQuery to verify mobile phone number, ID number, and Chinese name using regular expressions? -PHP Chinese website Q&A
Let’s take a look and learn.
伊谢尔伦2017-03-18 09:13:17
数字判断方法:isNaN()函数
test()方法 判断字符串中是否匹配到正则表达式内容,返回的是boolean值 ( true / false )
// 验证中文名称 function isChinaName(name) { var pattern = /^[\u4E00-\u9FA5]{1,6}$/; return pattern.test(name); } // 验证手机号 function isPhoneNo(phone) { var pattern = /^1[34578]\d{9}$/; return pattern.test(phone); } // 验证身份证 function isCardNo(card) { var pattern = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; return pattern.test(card); }