JS驗證input輸入框(字母,數(shù)字,符號,中文)
只能輸入英文
<input type="text" onkeyup="value=value.replace(/[^a-zA-Z]/g,'')">
只能輸入英文
<input type="text" onkeyup="value=value.replace(/[^\a-\z\A-\Z]/g,'')" onkeydown="fncKeyStop(event)" onpaste="return false" oncontextmenu="return false" />
無法粘貼,右鍵不會彈出粘貼菜單
只能輸入數(shù)字:
<input onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
只能輸入數(shù)字,小數(shù)點:
<input name="price" type="text" onkeyup="value=value.replace(/[^\d\.]/g,'')">
只能輸入數(shù)字,小數(shù)點,下劃線:
<input name="price" type="text" onkeyup="value=value.replace(/[^\d\._]/g,'')">
只能輸入英文和數(shù)字:
<input onkeyup="value=value.replace(/[\W]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
只能輸入漢字:
<input onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))">
禁止輸入法輸入:
<input type="text" style="ime-mode: disabled">
無法切換輸入法
只能輸入中文、英文、數(shù)字、@符號和.符號:
<input type="text" onkeyup="value=value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\@\.]/g,'')">
不能為空:
<input onblur="if(this.value.replace(/^ +| +$/g,'')=='')alert('不能為空!')">
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!
- vue.js 1.x與2.0中js實時監(jiān)聽input值的變化
- JS中input表單隱藏域及其使用方法
- js監(jiān)聽input輸入框值的實時變化實例
- JS獲得多個同name 的input輸入框的值的實現(xiàn)方法
- JS文件上傳神器bootstrap fileinput詳解
- JS獲取input file絕對路徑的方法(推薦)
- JS通過正則限制 input 輸入框只能輸入整數(shù)、小數(shù)(金額或者現(xiàn)金) 兩位小數(shù)
- JavaScript獲取并更改input標(biāo)簽name屬性的方法
- js與jquery實時監(jiān)聽輸入框值的oninput與onpropertychange方法
- js form表單input框限制20個字符,10個漢字代碼實例
相關(guān)文章
quickjs調(diào)用lvgl函數(shù)的示例代碼
這篇文章主要介紹了quickjs調(diào)用lvgl函數(shù),實現(xiàn)本次使用quickjs的最主要目的,就是通過程序動態(tài)加載js,然后調(diào)用lvgl函數(shù)庫,實現(xiàn)渲染,需要的朋友可以參考下2023-11-11Electron中實現(xiàn)大文件上傳和斷點續(xù)傳功能
Electron是開源的框架,可以使用h5來開發(fā)跨平臺pc桌面應(yīng)用,這樣前端開發(fā)這可以開發(fā)桌面應(yīng)用了。這篇文章主要介紹了Electron中實現(xiàn)大文件上傳和斷點續(xù)傳功能,需要的朋友可以參考下2018-10-10JS實現(xiàn)仿FLASH效果的豎排導(dǎo)航代碼
這篇文章主要介紹了JS實現(xiàn)仿FLASH效果的豎排導(dǎo)航代碼,涉及JavaScript基于定時函數(shù)動態(tài)設(shè)置頁面元素樣式的技巧,具有FLASH變換效果,需要的朋友可以參考下2015-09-09JavaScript實現(xiàn)單擊網(wǎng)頁任意位置打開新窗口與關(guān)閉窗口的方法
這篇文章主要介紹了JavaScript實現(xiàn)單擊網(wǎng)頁任意位置打開新窗口與關(guān)閉窗口的方法,涉及javascript窗口的相關(guān)操作函數(shù)與使用技巧,需要的朋友可以參考下2017-09-09