JS Latest mobile phone number, phone number regular expression
Regular expressions (regular expression) are an object that describes the character pattern. Using javascript Regular expressions, you can perform powerful pattern matching and text retrieval and replacement functions.
Cell phone number Regular expression validation.
function checkPhone(){ var phone = document.getElementById(‘phone‘).value; if(!(/^1[3|4|5|7|8]\d{9}$/.test(phone))){ alert("手机号码有误,请重填"); return false; } }
Here's a simple explanation:
^1[3|4|5|7|8]\d{9}$
The expression starts with 1, the second bit may be any one of the 3/4/5/7/8, and the next \d represents the 9 bits of the number [0-9], which adds up to 11 bits in total.
Please refer to this article for details: JS Latest mobile phone number test regular expression (you can definitely understand)
I guess you might like the article about JavaScript Regular: regular
- Summary of regular expressions in JavaScript (lots of regular)
- JavaScript regular Expressions (example)
Fixed phone number Regular expression:
function checkTel(){ var tel = document.getElementById(‘tel‘).value;if(!/^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/.test(tel)){alert(‘固定电话有误,请重填‘);return false;}}
ID Card Regular:
//身份证正则表达式(15位)isIDCard1=/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/;//身份证正则表达式(18位)isIDCard2=/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{4}$/;身份证正则合并:(^\d{15}$)|(^\d{17}([0-9]|X)$)
Latest mobile phone number regular expression: January 2016 13 Update, the following is no longer used
var tel = $("#telNo").val(); //获取手机号var telReg = !!tel.match(/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/);//如果手机号码不能通过验证if(telReg == false){ }
2015-11-20 (new compatible phone and mobile phone)
(\d{11}) |^ ((\d{7,8}) | ( \D{4}|\D{3})-(\d{7,8}) | (\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}) | (\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))
Match format:
11-digit Mobile phone number
3-4-bit area code, 7-8-digit live number, 1-4 poorly transposition machine number
such as: 12345678901, 1234-12345678-1234
Use the same way:
var telReg = !!tel.match(/^((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)$/);//如果通过认证if(telReg){}
Other
提取信息中的网络链接:(h|H)(r|R)(e|E)(f|F) *= *(‘|")?(\w|\\|\/|\.)+(‘|"| *|>)?提取信息中的邮件地址:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*提取信息中的图片链接:(s|S)(r|R)(c|C) *= *(‘|")?(\w|\\|\/|\.)+(‘|"| *|>)?提取信息中的IP地址:(\d+)\.(\d+)\.(\d+)\.(\d+)提取信息中的中国手机号码:(86)*0*13\d{9}提取信息中的中国固定电话号码:(\(\d{3,4}\)|\d{3,4}-|\s)?\d{8}提取信息中的中国电话号码(包括移动和固定电话):(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}提取信息中的中国邮政编码:[1-9]{1}(\d+){5}提取信息中的中国身份证号码:\d{18}|\d{15}提取信息中的整数:\d+提取信息中的浮点数(即小数):(-?\d*)\.?\d+提取信息中的任何数字 :(-?\d*)(\.\d+)?提取信息中的中文字符串:[\u4e00-\u9fa5]*提取信息中的双字节字符串 (汉字):[^\x00-\xff]*
Use:
The test () method looks in the string for the presence of the specified regular expression and returns a Boolean value that returns true if it exists, otherwise false.
var pattern = new RegExp(‘Box‘,‘i‘);var str = ‘box‘;alert(pattern.test(str)); //truevar pattern = /Box/i;var str = ‘box‘;alert(pattern.test(str)); //truevar pattern = /Box/i;var str = ‘This is a box‘;alert(pattern.test(str)); //true
Http://caibaojian.com/regexp-example.html
JS Latest mobile phone number, phone number regular expression