[easyUI]手機號固定位數校驗

<%  
    String path = request.getContextPath();  
    request.setAttribute("base", path);  
%>

<form id="sellerEditForm" class="sellerEditForm" method="post">
   <table cellpadding="5">
        <tr>
            <td>手機號:</td>
            <td><input id="phonenum" name="phonenum" class="easyui-numberbox" type="text" data-options="precision:0,required:true" /></td>
        </tr> 
    </table>
</form>

點擊提交按鈕,觸發submitForm函數:

function submitForm(){
	if(!$('#sellerEditForm').form('validate')){
		$.messager.alert('提示','表單還未填寫完成!');
		return ;
	}
        //手機號固定位數校驗 
	var phonenum = $('#phonenum').numberbox('getValue');
	//alert(phonenum);
	if(phonenum.length == 11){
		$.post("${base}/seller/edit",$("#sellerEditForm").serialize(), function(data){
			if(data.status == 200){ //返回成功
				$.messager.alert('提示','修改分銷商成功!','info',function(){ 
					$("#sellerEditWindow").window('close');
					$("#sellerList").datagrid("reload");	
				});
			}else{
				$.messager.alert('提示','手機號已經被使用,修改失敗!','error');
				$("#phonenum").numberbox().next('span').find('input').focus();//定位光標
				return;
			}
		});
	}else{
		$.messager.show({
			title : '提示',
			msg : "手機號碼必須是11位數字!",
			showType : 'slide',
			timeout:3000,
			showSpeed:400,//定義窗口顯示的過度時間。默認:600毫秒
		});
		$("#phonenum").numberbox().next('span').find('input').focus();//定位光標
		return;
	}
}
以上實現了:
        1. 手機號固定位數校驗 11位數字;
                     (1) easyui-numberbox: 強制必須輸入數字
                     (2) required:true: 強制必須輸入
         2. 編輯完成後,編輯窗口關閉,表格數據自動刷新
         3. 如果輸入錯誤,通過$.messager.show自動彈窗提示,略過鼠標點擊從而能夠實現光標定位(到錯誤處)

jQuery easyUI 技術支持鏈接: http://www.jeasyui.net/
  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章