3 整数正则
//正整数正则 var posPattern = /^\d+$/; //负整数正则 var negPattern = /^-\d+$/; //整数正则 var intPattern = /^-?\d+$/; //输出 true console.log(posPattern.test("42")); //输出 true console.log(negPattern.test("-42")); //输出 true console.log(intPattern.test("-42"));4 数字正则
可以是整数也可以是浮点数
//正数正则 var posPattern = /^\d*\.?\d+$/; //负数正则 var negPattern = /^-\d*\.?\d+$/; //数字正则 var numPattern = /^-?\d*\.?\d+$/; console.log(posPattern.test("42.2")); console.log(negPattern.test("-42.2")); console.log(numPattern.test("-42.2"));5 Email正则
//Email正则 var ePattern = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; //输出 true console.log(ePattern.test(65974040@qq.com));6 手机号码正则
//手机号正则 var mPattern = /^[1][3][0-9]{9}$/; //输出 true console.log(mPattern.test("13900000000"));