JS校驗表單(包括電話,郵編,手機號等等)
function isMail(obj,str,allowNull) { var pattern = /^([a-zA-Z0-9_-])[email protected]([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/; if(!isNotNull(obj,str,allowNull)) return false; if(!(pattern.test(obj.value))&&!isNull(obj)){ //document.getElementById('doing').style.visibility='hidden'; alert(str+" 不是合法電子郵件格式!"); obj.focus(); return false; } else return true; } //非法字元校驗,以英文字母開頭其後只能包含英文字母、數字及"_" function isEN(obj,str,allowNull) { var pattern = /^([a-zA-Z])+([a-zA-Z0-9_]*)+$/; if(!isNotNull(obj,str,allowNull)) return false; if(!(pattern.test(obj.value))&&!isNull(obj)){ //document.getElementById('doing').style.visibility='hidden'; alert(str+" 必須以英文字母開頭其後只能包含英文字母、數字及'_'"); obj.focus(); return false; } else return true; } function isNotNull (obj,str,allowNull){ if (isNull(obj) && !allowNull){ // document.getElementById('doing').style.visibility='hidden'; alert(str+" 不能為空!"); obj.focus(); return false; } else return true; } function isNotNull1 (obj,str,allowNull){ if ((isNull(obj)||trim(obj.value)=="null") && !allowNull){ //document.getElementById('doing').style.visibility='hidden'; alert(str+" 不能為空!"); obj.focus(); return false; } else return true; } function isNull(obj){ if(!obj.value || trim(obj.value)=="") return true; else return false; } // function isNumber(obj,str,allowNull) { var pattern =/^[-,+]{0,1}[0-9]{0,}[.]{0,1}[0-9]{0,}$/; if(!isNotNull(obj,str,allowNull)) return false; if(!(pattern.test(obj.value))&&!isNull(obj)){ // document.getElementById('doing').style.visibility='hidden'; alert(str+" 不是數字格式!"); obj.focus(); return false; } else return true; } function isInteger(obj,str,allowNull) { var pattern = /^-*\d+$/; if(!isNotNull(obj,str,allowNull)) return false; if(!(pattern.test(obj.value))&&!isNull(obj)){ // document.getElementById('doing').style.visibility='hidden'; alert(str+" 不是整數格式!"); obj.focus(); return false; } else return true; } function isIntegerInfo(obj,str,allowNull) { var pattern = /^-*\d+$/; if(!isNotNull(obj,str,allowNull)) return false; if(!(pattern.test(obj.value))&&!isNull(obj)){ //document.getElementById('doing').style.visibility='hidden'; alert(str); obj.focus(); return false; } else return true; } function isDate(obj,str,allowNull) { var pattern = /^[1-9]\d{3}[/|-]((0[1-9])|(1(0|1|2))|([1-9]))[/|-](([0-2][1-9])|([1-2][0-9])|(3(0|1))|([1-9]))$/; if(!isNotNull(obj,str,allowNull)) return false; if(!(pattern.test(obj.value))&&!isNull(obj)){ //document.getElementById('doing').style.visibility='hidden'; alert(str+" 不是日期格式!"); obj.focus(); return false; } else return true; } function verifyPassword(obj1, obj2) { if (obj1.value != obj2.value) { // document.getElementById('doing').style.visibility='hidden'; alert("輸入的密碼不一致!"); return false; } return true; } function checkMobile(obj,str,allowNull){ var pattern=/^((\(\d{2,3}\))|(\d{3}\-))?13\d{9}$/; if(!isNotNull(obj,str,allowNull)) return false; if(!(pattern.test(obj.value))&&!isNull(obj)){ // document.getElementById('doing').style.visibility='hidden'; alert(str+" 格式不對!"); obj.focus(); return false; } else return true; } /**********驗證身份證號碼的有效性***********/ function isIdCard(obj,str,allowNull){ var pattern = /^\d{15}(\d{2}[A-Za-z0-9])?$/; if(!isNotNull(obj,str,allowNull)) return false; if(!(pattern.test(obj.value))&&!isNull(obj)){ // document.getElementById('doing').style.visibility='hidden'; alert(str+" 不是正確的身份證號碼!"); obj.focus(); return false; } else return true; } /**********驗證手機號碼的有效性***********/ function isMobile(obj,str,allowNull){ var pattern = /^((\(\d{3}\))|(\d{3}\-))?13\d{9}$/; if(!isNotNull(obj,str,allowNull)) return false; if(!(pattern.test(obj.value))&&!isNull(obj)){ // document.getElementById('doing').style.visibility='hidden'; alert(str+" 不是正確的手機號碼!"); obj.focus(); return false; } else return true; } /**********驗證電話號碼的有效性***********/ function isTel(obj,str,allowNull){ var pattern = /^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$/; if(!isNotNull(obj,str,allowNull)) return false; if(!(pattern.test(obj.value))&&!isNull(obj)){ // document.getElementById('doing').style.visibility='hidden'; alert(str+" 不是正確的電話號碼!"); obj.focus(); return false; } else return true; } /**********驗證email的有效性***********/ function isEmail(obj,str,allowNull){ var pattern = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/; if(!isNotNull(obj,str,allowNull)) return false; if(!(pattern.test(obj.value))&&!isNull(obj)){ // document.getElementById('doing').style.visibility='hidden'; alert(str+" 不是正確的E_mail!"); obj.focus(); return false; } else return true; } /**********驗證IP地址的有效性***********/ function isIp(obj,str,allowNull){ if(!isNotNull(obj,str,allowNull)) return false; var check=function(v){try{return (v<=255 && v>=0)}catch(x){return false}}; var re=obj.value.split("."); //return (re.length==4)?(check(re[0]) && check(re[1]) && check(re[2]) && check(re[3])):false; if((re.length==4)?(check(re[0]) && check(re[1]) && check(re[2]) && check(re[3])):false &&!isNull(obj)){ // document.getElementById('doing').style.visibility='hidden'; alert(str+" 不是正確的IP!"); obj.focus(); return false; } else return true; } /**********驗證只能為數字或字母***********/ function isNumOrE(obj,str,allowNull){ var pattern = new RegExp("^[a-zA-Z0-9]+{1}quot;); if(!isNotNull(obj,str,allowNull)) return false; if(!(pattern.test(obj.value))&&!isNull(obj)){ // document.getElementById('doing').style.visibility='hidden'; alert(str+"只能數字或者字母!"); obj.focus(); return false; } else return true; } /**********驗證郵政編碼的有效性***********/ function isZip(obj,str,allowNull){ var pattern = /^[1-9]\d{5}$/; if(!isNotNull(obj,str,allowNull)) return false; if(!(pattern.test(obj.value))&&!isNull(obj)){ // document.getElementById('doing').style.visibility='hidden'; alert(str+" 不是正確的郵政編碼!"); obj.focus(); return false; } else return true; } /**********去除左右空格***********/ function trim(str){ return str.replace(/(^\s*)|(\s*$)/g, ""); } /* function isNumber(obj) { var pattern =/^[-,+]{0,1}[0-9]{0,}[.]{0,1}[0-9]{0,}$/; var oldValue = obj.value; if(!(pattern.test(obj.value))){ document.getElementById('doing').style.visibility='hidden'; alert("不是數字格式!"); obj.value = oldValue; obj.focus(); return false; } else return true; }*/ function strToDate(str) { var arys= new Array(); arys=str.split('-'); var newDate=new Date(arys[0],arys[1],arys[2]); return newDate; }
相關推薦
JS校驗表單(包括電話,郵編,手機號等等)
function isMail(obj,str,allowNull) { var pattern = /^([a-zA-Z0-9_-])[email protected]([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/; if(!isNo
js校驗表單資料
//新增驗證規則 jQuery.validator.addMethod("chcharacter",function (value, element) { var tel = /^[\一-\龥]+$/
使用者註冊介面js校驗+表單提示
// 使用者名稱 function YHMonblus(){ var username=document.getElementById("username"); // var reN =/^\d{6,18}$/; var re = /^[a-zA-
iview動態校驗表單,獲取值為undefined
場景:實際程式碼如下:https://run.iviewui.com/XPofr3YS 原因:在動態校驗名稱時,沒法獲取值,請教了大神後,發現原來是自己demo沒理清楚 這裡的prop="name"應該是動態的,從新梳理demo 解決:程式碼應
jQuery Validate 實現儲存時不校驗,提交時才校驗表單
//儲存按鈕事件 function saveAction() {var form = $("#inputForm").find('.required');$.each(form, function(idx, item) {$(this).addClass('ignore');}
20181006:為什麼要使用form表單而不是直接用html模板?校驗表單是怎樣處理的?
使用者登入流程:在forms.py中自己定義定義loginform類(其中包含登陸的表單,比如賬號、密碼、提交按鈕等)→ views.py中路由控制跳轉到登陸頁面模板(在其中傳入form),使用者輸入了賬號、密碼後點擊“提交”按鈕後,前端、後端校驗完成後,跳轉到
validate外掛校驗表單--自定義校驗,Ajax非同步校驗使用者名稱是否存在
1.所需要的外掛下載地址(放到js目錄下)https://pan.baidu.com/s/16KyrX16dzgGTIncho2WHmg2.引入庫<script src="js/jquery.validate.min.js" type="text/javascript"
onsubmit校驗表單時利用ajax的return false無效解決方法
原來的程式碼 function checkNewEmail(){ var re_email=new RegExp("\\[email protected]\\w+\\.\\w+\\.?\\w*"); var ne
Spring Boot構建的Web專案如何在服務端校驗表單輸入
本文首發於個人網站:Spring Boot構建的Web專案如何在服務端校驗表單輸入 這個例子用於演示在Spring Boot應用中如何驗證Web 應用的輸入,我們將會建立一個簡單的Spring MVC應用,來讀取使用者輸入並使用validation註解來檢查,並且當用戶輸入錯誤時,應用需要再螢幕上顯示錯誤
Spring Boot (一) 校驗表單重複提交
一、前言 在某些情況下,由於網速慢,使用者操作有誤(連續點選兩下提交按鈕),頁面卡頓等原因,可能會出現表單資料重複提交造成資料庫儲存多條重複資料。 存在如上問題可以交給前端解決,判斷多長時間內不能再次點選儲存按鈕,當然,如果存在聰明的使用者能夠繞過前端驗證,後端更應該去進行攔截處理,下面小編將基於 Sprin
使用easyUI中的jquery.validate.min.js外掛進行表單驗證並自定義校驗規則
以前使用原生的js或者jQuery寫表單驗證真的好麻煩,使用上面的easyUI外掛配合著ajax真的節省好多程式碼量直接上程式碼<%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%&g
js 監測from表單中的input和select,時時監測,沒有輸入或選擇信息報錯,不允許提交數據
height ssss txt input OS 表達 tip eight html 1.html 代碼為 在input和select同級元素中添加 .error的標簽,用來存放報錯信息 <form action="" method="post" enctype="
input只輸入數字和js校驗是否輸入框只有數字以及游標放輸入框時,輸入框裡內容消失
input只輸入數字和js校驗是否輸入框只有數字以及游標放輸入框時,輸入框裡內容消失 input框只能輸入數字: 1 onkeyup="value=value.replace(/[^\d]/g,'')" js校驗是否是純數字 1 if(isNaN(bankAccountNo)){ 2
MyEclipse提供比較嚴謹的js校驗功能,因此ExtJs、jQuery等前端框架匯入到MyEclipse後均會提示錯誤,解決辦法
方法一: 1、在MyEclipse選擇選單欄window 2、選擇preferences 3、左側選單樹中展開myeclipse 4、選擇下面的validation 5、將右側表格中javascript validator for Js files 把Buli
在JS中模擬表單的post提交,進行頁面的跳轉
封裝為Post(URL, PARAMTERS) 函式: /* *功能: 模擬form表單的提交 *引數: URL 跳轉地址 PARAMTERS 引數 */ function Post(URL
js提交form表單,並傳遞引數
//增加的函式 begin function queryFun(){ var type = $("#artType").val(); var hasInputed = "1";//表示輸入了要搜尋 的資訊 if($("#query").val()=="選手姓名/編號"){
js 簡單實現表單資料的增添,單項刪改,多項刪除,修改以及全選功能
// 新增商品函式 function add(){ // 獲取表單元素 var table = document.getElementById("order"); // 以表單的行數為索引插入行
js校驗日期, 除週六周天。
function checkDate(){ var d = new Date(); var str = d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate(); var
js動態控制表單的tr,td的顯示和隱藏
無論是事先寫好的,還是動態生成的,要找到指定的tr或td都必須知道其相關的一個屬性,未必必須是id或name,然後無論是在一個table還是多個 table都可以通過document.getElementsByTagNames( "tr ")或td,取得集合,……再根據知道
js驗證表單 驗證空值 長度,過濾非數字等
3、<!-- 驗證表單的js提交方式會不一樣 --><script type="text/javascript">function checkFormSubmit(form){if(form.username.value == ""){alert("請輸入賬號");form.usern