作者:0o可人儿o0_962 | 来源:互联网 | 2023-09-18 09:28
正整数&#xff1a; < el-inputstyle&#61; "width: 200px" v-model&#61; "formSearchData.period" &#64;input&#61; "(val) &#61;> {formSearchData.period &#61; val.replace(/[^\d]/g, &#39;&#39;);}" placeholder&#61; "计划期数" > < /el-input>
0-100分数验证&#xff1a; var examRule &#61; function( rule, value, callback) { //分数验证if( value !&#61; &#39;&#39; && value !&#61; null) { let examScore &#61; parseInt( value) ; if( examScore < 0 || examScore > 100) { callback( new Error( &#39;请输入正确的考试成绩&#39; )) ; } else{ callback( ) ; } } else{ callback( ) ; } } ;
页面 rules: { examScore: [ { required: true, message: "请输入考试成绩" , trigger: "blur" } ,{ validator: examRule, trigger: &#39;blur&#39; } ,//examRule&#xff1a;0-100验证{ validator: IsInteger, trigger: &#39;blur&#39; } ,//IsInteger:正整数验证] } ,
1 用户名正则 //用户名正则&#xff0c;4到16位&#xff08;字母&#xff0c;数字&#xff0c;下划线&#xff0c;减号&#xff09; var uPattern &#61; /^[ a-zA-Z0-9_-] { 4,16} $/; //输出 true console.log( uPattern.test( "caibaojian" )) ;
2 密码强度正则 //密码强度正则&#xff0c;最少6位&#xff0c;包括至少1个大写字母&#xff0c;1个小写字母&#xff0c;1个数字&#xff0c;1个特殊字符 var pPattern &#61; /^.*( ?&#61; .{ 6,} ) ( ?&#61; .*d) ( ?&#61; .*[ A-Z] ) ( ?&#61; .*[ a-z] ) ( ?&#61; .*[ ! &#64; //输出 true console.log( "&#61;&#61;" &#43;pPattern.test( "caibaojian#" )) ;
3 整数正则 //正整数正则 var posPattern &#61; /^d&#43;$/; //负整数正则 var negPattern &#61; /^-d&#43;$/; //整数正则 var intPattern &#61; /^-?d&#43;$/; //输出 true console.log( posPattern.test( "42" )) ; //输出 true console.log( negPattern.test( "-42" )) ; //输出 true console.log( intPattern.test( "-42" )) ;
4 数字正则 可以是整数也可以是浮点数 //正数正则 var posPattern &#61; /^d*.?d&#43;$/; //负数正则 var negPattern &#61; /^-d*.?d&#43;$/; //数字正则 var numPattern &#61; /^-?d*.?d&#43;$/; console.log( posPattern.test( "42.2" )) ; console.log( negPattern.test( "-42.2" )) ; console.log( numPattern.test( "-42.2" )) ;
5 Email正则 //Email正则 var ePattern &#61; /^( [ A-Za-z0-9_-.] ) &#43;&#64;( [ A-Za-z0-9_-.] ) &#43;.( [ A-Za-z] { 2,4} ) $/; //输出 true console.log( ePattern.test( "99154507&#64;qq.com" )) ;
6 手机号码正则 //手机号正则 var mPattern &#61; /^1[ 34578] d{ 9} $/; //http://caibaojian.com/regexp-example.html //输出 true console.log( mPattern.test( "15507621888" )) ;
7 身份证号正则 //身份证号&#xff08;18位&#xff09;正则 var cP &#61; /^[ 1-9] d{ 5} ( 18| 19| ( [ 23] d)) d{ 2} (( 0 [1 - 9 ]) | ( 10 | 11 | 12 )) (( [ 0-2] [ 1-9] ) | 10| 20| 30| 31) d{ 3} [ 0-9Xx] $/; //输出 true console.log( cP.test( "11010519880605371X" )) ;
8 URL正则 //URL正则 var urlP&#61; /^(( https?| ftp | file) ://) ?( [ da-z.-] &#43;) .( [ a-z.] { 2,6} ) ( [ /w .-] *) */?$/; //输出 true console.log( urlP.test( "http://caibaojian.com" )) ;
9 IPv4地址正则 //ipv4地址正则 var ipP &#61; /^( ?:( ?:25[ 0-5] | 2[ 0-4] [ 0-9] | [ 01] ?[ 0-9] [ 0-9] ?) .) { 3} ( ?:25[ 0-5] | 2[ 0-4] [ 0-9] | [ 01] ?[ 0-9] [ 0-9] ?) $/; //输出 true console.log( ipP.test( "115.28.47.26" )) ;
10 十六进制颜色正则 //RGB Hex颜色正则 var cPattern &#61; /^ //输出 true console.log( cPattern.test( "#b8b8b8" )) ;
11 日期正则 //日期正则&#xff0c;简单判定,未做月份及日期的判定 var dP1 &#61; /^d{ 4} ( -) d{ 1,2} 1d{ 1,2} $/; //输出 true console.log( dP1.test( "2017-05-11" )) ; //输出 true console.log( dP1.test( "2017-15-11" )) ; //日期正则&#xff0c;复杂判定 var dP2 &#61; /^( ?:( ?! 0000) [ 0-9] { 4} -( ?:( ?:0[ 1-9] | 1[ 0-2] ) -( ?:0[ 1-9] | 1[ 0-9] | 2[ 0-8] ) | ( ?:0[ 13-9] | 1[ 0-2] ) -( ?:29| 30) | ( ?:0[ 13578] | 1[ 02] ) -31) | ( ?:[ 0-9] { 2} ( ?:0[ 48] | [ 2468] [ 048] | [ 13579] [ 26] ) | ( ?:0[ 48] | [ 2468] [ 048] | [ 13579] [ 26] ) 00) -02-29) $/; //输出 true console.log( dP2.test( "2017-02-11" )) ; //输出 false console.log( dP2.test( "2017-15-11" )) ; //输出 false console.log( dP2.test( "2017-02-29" )) ;
12 QQ号码正则 //QQ号正则&#xff0c;5至11位 var qqPattern &#61; /^[ 1-9] [ 0-9] { 4,10} $/; //输出 true console.log( qqPattern.test( "65974040" )) ;
13 微信号正则 //微信号正则&#xff0c;6至20位&#xff0c;以字母开头&#xff0c;字母&#xff0c;数字&#xff0c;减号&#xff0c;下划线 var wxPattern &#61; /^[ a-zA-Z] ( [ -_a-zA-Z0-9] { 5,19} ) &#43;$/; //输出 true console.log( wxPattern.test( "caibaojian_com" )) ;
14 车牌号正则 //车牌号正则 var cPattern &#61; /^[ 京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z] { 1} [ A-Z] { 1} [ A-Z0-9] { 4} [ A-Z0-9挂学警港澳] { 1} $/; //输出 true console.log( cPattern.test( "粤B39006" )) ;
15 包含中文正则 //包含中文正则 var cnPattern &#61; /[ u4E00-u9FA5] /; //输出 true console.log( cnPattern.test( "蔡宝坚" )) ;