邮箱,手机号,电话号,身份证,中文名称验证
<script type="text/javascript">
//验证邮箱
function emailZ(obj){
var email=document.getElementById(obj).value;
if(email!=""){
if(!email.match(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/))
{
alert("The mailbox format is incorrect! Please re-enter");
$("#"+obj).val("");
$("#"+obj).focus();
return false;
}
}
}
// 验证手机号
function isPhoneNo(phone) {
var pattern=document.getElementById(phone).value;
if(pattern!=""){
if(!pattern.match(/^1[34578]\d{9}$/))
{
alert("The phone number is not in the correct format! Please re-enter");
$("#"+phone).val("");
$("#"+phone).focus();
return false;
}
}
}
// 验证电话号
function isContact(phone) {
var pattern=document.getElementById(phone).value;
if(pattern!=""){
if(!pattern.match(/^((0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/))
{
alert("The phone number is not in the correct format! Please re-enter Such as:0321-4816048");
$("#"+phone).val("");
$("#"+phone).focus();
}
}
}
// 验证身份证
function isCardNo(phone) {
var identity=document.getElementById("identitySourceId").value;
var pattern=document.getElementById(phone).value;
if(identity==""){
if(pattern!=""){
alert("Please select the document type first");
$("#"+phone).val("");
$("#identitySourceId").focus();
}
}else{
if(pattern!="" && identity=="1"){
if(!pattern.match(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/))
{
alert("The ID card is not in the correct format! Please re-enter");
$("#"+phone).val("");
$("#"+phone).focus();
return false;
}
}
}
}
// 验证中文名称
function isChinaName(phone) {
var pattern=document.getElementById(phone).value;
if(pattern!=""){
if(!pattern.match(/^[\u4E00-\u9FA5]{1,6}$/))
{
alert("The input is not in Chinese. Please enter chinese.");
$("#"+phone).val("");
$("#"+phone).focus();
}
}
}
//只能为整数或者两位小数
if(amount != "" && amount != null){
if (!(/^\d+(\.\d{1,2})?$/.test(amount))) {
alert("Billable Amount 只能为整数或者两位小数");
$("#billableAmount").val("");
$("#billableAmount").focus();
return false;
}
}
//格式化为0,验证填入时间不能为负数,验证填入时间必须为0.5的倍数
function Initialization(a,b){
//格式化为0
if(document.getElementById(a).value==""){
$("#"+a).val(0);
return false;
}
//验证填入时间不能为负数
if(document.getElementById(a).value<0){
alert("Please fill in the correct number of hours (not negative)");
$("#"+a).focus();
$("#"+a).val("");
return false;
}
//验证填入时间必须为0.5的倍数
var chack = /^\d*(\.(5|0))?$/;
if(!chack.test($("#"+a).val())){
alert(b+" Data must be a multiple of 0.5");
$("#"+a).focus();
$("#"+a).val("");
return false;
}
}
</script>