1. 程式人生 > >校驗檔案

校驗檔案

1、手機號碼:var phone=/^[1][358]\d{9}$/;
2、固定電話:var tel =/^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$/;
3、郵箱:var mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
4、身份證:var card = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{4}$/;

備註:錯誤樣式 紅色style = "color: #ff0000"

5、只能輸入數字,且不能以0開頭
onkeyup="this.value=(parseInt((this.value=this.value.replace(/\D/g,''))==''?'0':this.value,10)==0?'':this.value)"

onkeyup="clearNoNum(this)"
function clearNoNum(obj){ 
    //先把非數字的都替換掉,除了數字和. 
    obj.value = obj.value.replace(/[^\d.]/g,""); 
    //必須保證第一個為數字而不是. 
    //不能以‘.’開頭,如果是整數不能以0開關
    obj.value = obj.value.replace(/^\./g,"").replace(/^0[^\.]/g,"");
    //保證只有出現一個.而沒有多個. 
    obj.value = obj.value.replace(/\.{2,}/g,"."); 
    //保證.只出現一次,而不能出現兩次以上 
    obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$","."); 
}

<inputonkeyup="this.value=this.value.replace(/D/g,‘‘)"onafterpaste="this.value=this.value.replace(/D/g,‘‘)">

onkeyup="if(value.match(/^\d{3}$/))value=value.replace(value,parseInt(value/10)) ;
onkeyup="if(value.match(/^\d{3}$/))value=value.replace(value,parseInt(value/10)) ;value=value.replace(/\.\d*\./g,.)"
<input name=txt1onchange="if(/D/.test(this.value)){alert(‘只能輸入數字‘);this.value=‘‘;}">

1.日期:大於當前日期
onfocus="WdatePicker({minDate:'#F{$dp.$D(\'startDate\')||\'%y-%M-%d\';}'})"

<input type="text" class="startDate" id="startDate" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'startDate\')||\'%y-%M-%d\';}'})">

<input class="Wdate" id="startDate" type="text" 
onClick="WdatePicker({startDate:'%y-%M-%d',minDate:'#F{$dp.$D(\'endDate\',{y:-1});}',maxDate:'#F{$dp.$D(\'endDate\')||\'%y-%M-%d\';}'});" /> 
<input class="Wdate" type="text" id="endDate" 
onClick="WdatePicker({startDate:'%y-%M-%d',minDate:'#F{$dp.$D(\'startDate\');}',maxDate:'%y-%M-%d'});" />

2、只能輸入數字(http://chenfengcn.iteye.com/blog/555631)
onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"

2、只能輸入數字和小數點
<input type="text" class="hid-input guaranteeAmount" onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')"
onBlur="this.value=this.value.replace(this.value,this.value==''?'':this.value+'(元)')"/>

3、比例
onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" onBlur="this.value=this.value.replace(this.value,this.value/100)"


4、合計
onblur="floatInput(this);sumColFloat('agingTb', 1, 'agingTbSumTr');">

function initMajorCustomer() {
	var custId = $('#left li.selected').attr('data-id');
	var type = REPORT_CONSTANT.TYPE.CRED.MCS;
	var params = {custId: custId, type:type};
	$.post(getRootPath() + '/annexCredit/findAnnexAndDetail', params, function(data) {
		$('#majorCustomerExportBtn').attr('onclick', "exportSheetByIdAndType('" + ((data.data.annex && data.data.annex != null) ? data.data.annex.id : '') + "', " + type + ")");
		var template=$('#majorCustomerTpl').html();
		$("#majorCustomerTb tbody").html(doT.template(template)(data.data));
		sumColsFloat('majorCustomerTb', [1, 2], 'majorCustomerSumTr');
		sumColsInt('majorCustomerTb', [4, 5], 'majorCustomerSumTr');
	});
}