<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> Form validation </title>
<script language="javascript">
function check_1(param){//Don't empty
if(param==""||param==null){return false;}else{return true;}
}
function check_2(param){//The length limit is 10 letters and 10 characters
if(param.length>10){return false;}else{return true;}
}
function check_3(param){//Can only input Chinese characters
var pattern= /^[u4e00-u9faf]+$/;
var flag = pattern.test(param);
if(flag==false){return false;}else{return true;}
}
function check_4(param){//You can only enter Numbers
var pattern= /^[0-9]+$/;
var flag = pattern.test(param);
if(flag==false){return false;}else{return true;}
}
function check_5(param){//Only alphanumeric underscores can be entered
var pattern= /^[0-9a-zA-z_]+$/;
var flag = pattern.test(param);
if(flag==false){return false;}else{return true;}
}
function check_6(param){//Mailbox format validation
var pattern= /^([a-zA-Z0-9]+[_|_|.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|_|.]?)*[a-zA-Z0-9]+.[a-zA-Z]{2,3}$/;
var flag = pattern.test(param);
if(flag==false){return false;}else{return true;}
}
function check_7(param){//Url format verification
var pattern= /^((https|http|ftp|rtsp|mms)?://)?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?(([0-9]{1,3}.){3}[0-9]{1,3}|([0-9a-z_!~*'()-]+.)*([0-9a-z][0-9a-z-]{0,61})?[0-9a-z].[a-z]{2,6})(:[0-9]{1,4})?((/?)|(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$/;
var flag = pattern.test(param);
if(flag==false){return false;}else{return true;}
}
function check(){
var value=document.getElementById("testValue").value;
var result=check_7(value);//In setting the name of the validation function here, I wrote check_1 to check_7 for the seven commonly used form validation functions
if(result==false){
document.getElementById("testValue").style.border="2px solid red";
}else{
//document.getElementById("testValue").style.border="2px solid green";
document.getElementById("testValue").style.border="";
}
}
</script>
</head>
<body>
<div style="text-align: center;padding: 200px 0;">
Please enter: <input id="testValue" name="" class="" type="text" style="width:200px;height:30px;"></input>
<input id="" name="" class="" type="button" value=" Click on the validation " style="width:70px;height:30px;" onclick="check()"></input>
</div>
</body>
</html>