Created
June 14, 2020 14:59
-
-
Save GeHou/9c6d717460d341be4805751f43c1d3bd to your computer and use it in GitHub Desktop.
正则表达式表单验证实例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*是否带有小数*/ | |
function isDecimal(strValue ) { | |
var objRegExp= /^\d+\.\d+$/; | |
return objRegExp.test(strValue); | |
} | |
/*校验是否中文名称组成 */ | |
function ischina(str) { | |
var reg=/^[\u4E00-\u9FA5]{2,4}$/; /*定义验证表达式*/ | |
return reg.test(str); /*进行验证*/ | |
} | |
/*校验是否全由8位数字组成 */ | |
function isStudentNo(str) { | |
var reg=/^[0-9]{8}$/; /*定义验证表达式*/ | |
return reg.test(str); /*进行验证*/ | |
} | |
/*校验电话码格式 */ | |
function isTelCode(str) { | |
var reg= /^((0\d{2,3}-\d{7,8})|(1[3584]\d{9}))$/; | |
return reg.test(str); | |
} | |
/*校验邮件地址是否合法 */ | |
function IsEmail(str) { | |
var reg=/^\w+@[a-zA-Z0-9]{2,10}(?:\.[a-z]{2,4}){1,3}$/; | |
return reg.test(str); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment