簡(jiǎn)介:公司網(wǎng)站做試用用戶申請(qǐng)窗口,為防止用戶錯(cuò)誤輸入,給予input適當(dāng)控制,能夠防止用戶輸入錯(cuò)誤,同時(shí)也能減少公司垃圾數(shù)據(jù),當(dāng)然,如果更大程度避免垃圾數(shù)據(jù),最好還是后端正則驗(yàn)證,下面是我記錄的input常用html' target='_blank'>正則表達(dá)式,希望能給大家?guī)?lái)方便。
( 推薦學(xué)習(xí):html教程 )
下面是input經(jīng)常用到正則表達(dá)式:
<!doctype html><html> <meta charset="utf-8" /> <body>只允許輸入正整數(shù): <input type='text' onkeyup="this.value=this.value.replace(/^(0+)|[^/d]+/g,'')"> <br/> <br/>只允許輸入英文: <input type="text" onkeyup="this.value=this.value.replace(/[^a-zA-Z]/g,'')"> <br/> <br/>只允許允許輸入數(shù)字和字母: <input onKeyUp="value=value.replace(/[/W]/g,'')"> <br/> <br/>允許輸入大小寫(xiě)字母、數(shù)字、下劃線: <input type="text" onkeyup="this.value=this.value.replace(/[^/w_]/g,'');"> <br/> <br/>允許輸入小寫(xiě)字母、數(shù)字、下劃線: <input type="text" onkeyup="this.value=this.value.replace(/[^a-z0-9_]/g,'');"> <br/> <br/>允許輸入數(shù)字和小數(shù)點(diǎn): <input type="text" onkeyup="this.value=this.value.replace(/[^/d.]/g,'')"> <br/> <br/>允許輸入中文、數(shù)字、英文: <input onkeyup="value=value.replace(/[^/w/u4E00-/u9FA5]/g, '')"> <br/> <br/> </body></html>
以上就是input輸入框只能輸入數(shù)字、字母相關(guān)組合(正則表達(dá)式)的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注 其它相關(guān)文章!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。
新聞熱點(diǎn)
疑難解答