html輸入驗證

2021-07-25 21:44:51 字數 1363 閱讀 3506

只能輸入和黏貼數字:οnkeyup="this.value=this.value.replace(/\d/g,'')" onafterpaste="this.value=this.value.replace(/\d/g,'')"

轉義:οnkeyup="this.value=this.value.replace(/\\d/g,\'\')" onafterpaste="this.value=this.value.replace(/\\d/g,\'\')"

只能輸入英文:onkeyup="value=value.replace(/[^a-za-z]/g,'')"

轉義:onkeyup="value=value.replace(/[^a-za-z]/g,\'\')"

年齡:οnkeyup="this.value=this.value.replace(/\d/g,'')" onafterpaste="this.value=this.value.replace(/\d/g,'')"

var inputadduserdetailage = document.getelementbyid("adduserdetailage");

inputadduserdetailage.onblur = function()

}

只能輸入數字和英文:οnkeyup="value=value.replace(/[\w]/g,'') " onbeforepaste="clipboarddata.setdata('text',clipboarddata.getdata('text').replace(/[^\d]/g,''))"

轉義:οnkeyup="value=value.replace(/[\\w]/g,\'\') " onbeforepaste="clipboarddata.setdata(\'text\',clipboarddata.getdata(\'text\').replace(/[^\\d]/g,\'\'))"

只能輸入數字,且最多兩位小數:οnkeyup= "this.value=this.value.replace(/[^\d.]/g,'');if( ! /^-?\d+\.?\d$/.test(this.value))"

轉義:οnkeyup="this.value=this.value.replace(/[^\\d.]/g,\'\');if( ! /^-?\\d+\\.?\\d$/.test(this.value))"

銀行卡:οnkeyup="this.value=this.value.replace(/\d/g,'').replace(/....(?!$)/g,'$& ')"

轉義:οnkeyup="this.value=this.value.replace(/\\d/g,\'\').replace(/....(?!$)/g,\'$& \')"

html 輸入框驗證

js判斷只能是數字和小數點 1.文字框只能輸入數字 小數點也不能輸入 2.只能輸入數字,能輸小數點.3.數字和小數點方法二 4.只能輸入字母和漢字 5.只能輸入英文本母和數字,不能輸入中文 6.只能輸入數字和英文chun 7.小數點後只能有最多兩位 數字,中文都可輸入 不能輸入字母和運算符號 57 ...

html 輸入框驗證

js判斷只能是數字和小數點 1.文字框只能輸入數字 小數點也不能輸入 2.只能輸入數字,能輸小數點.3.數字和小數點方法二 4.只能輸入字母和漢字 5.只能輸入英文本母和數字,不能輸入中文 6.只能輸入數字和英文chun 7.小數點後只能有最多兩位 數字,中文都可輸入 不能輸入字母和運算符號 57 ...

驗證數字輸入

static bool isnumeric string str return true 方法二 private bool isnumeric string s private bool isnumeric string s char ch0 0 char ch9 9 for int i 0 i s...