Home  >  Article  >  Web Front-end  >  How jQuery uses regular expressions to verify mobile phone number, ID number, and Chinese name

How jQuery uses regular expressions to verify mobile phone number, ID number, and Chinese name

高洛峰
高洛峰Original
2016-12-26 16:52:101421browse

Number judgment method: isNaN() function

test() method judges whether the regular expression content is matched in the string, and returns a boolean value (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); }

The above is the knowledge that the editor introduced to you on how jQuery uses regular expressions to verify mobile phone numbers, ID numbers, and Chinese names. I hope it will be helpful to you. If you have any questions, please leave me a message. The editor will reply to everyone in time. I would also like to thank you all for your support of the PHP Chinese website

For more articles on how jQuery uses regular expressions to verify mobile phone numbers, ID numbers, and Chinese names, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn