利用正則表達(dá)式(只錄入中文,數(shù)字,英文)
更新時(shí)間:2009年08月24日 02:15:29 作者:
利用正則表達(dá)式(只錄入中文,數(shù)字,英文)限制的代碼,好多情況下都需要。
只能輸入中文:<input id="input1" type="text" onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')">
只能輸入全角字符:<input id="input2" type="text" onkeyup="value=value.replac(/[^\u4E00-\u9FA5]/g,'')">
只能輸入數(shù)字:<input id="input3" type="text" onkeyup="value=value.replace(/[^\d]/g,'') ">
只能輸入數(shù)字和英文:<input id="input4" type="text" onkeyup="value=value.replace(/[\W]/g,'')">
只能輸入全角字符:<input id="input2" type="text" onkeyup="value=value.replac(/[^\u4E00-\u9FA5]/g,'')">
只能輸入數(shù)字:<input id="input3" type="text" onkeyup="value=value.replace(/[^\d]/g,'') ">
只能輸入數(shù)字和英文:<input id="input4" type="text" onkeyup="value=value.replace(/[\W]/g,'')">
相關(guān)文章
密碼強(qiáng)度的正則表達(dá)式兩種方案JS總結(jié)篇
本文給出了兩個(gè)密碼強(qiáng)度的正則表達(dá)式方案,一個(gè)簡(jiǎn)單,一個(gè)更復(fù)雜和安全。并分別給出了兩個(gè)方案的解析和測(cè)試程序。對(duì)密碼強(qiáng)度正則表達(dá)式的兩種方案感興趣的朋友跟隨腳本之家一起看看吧2018-03-03正則表達(dá)式Regular Expression (RegExp)詳解
正則表達(dá)式,又稱正規(guī)表示式、正規(guī)表示法、正規(guī)表達(dá)式、規(guī)則表達(dá)式、常規(guī)表示法(英語:Regular Expression,在代碼中常簡(jiǎn)寫為regex、regexp或RE2015-11-11淺談js正則字面量//與new RegExp的執(zhí)行效率
以前看到很多文章都說 字面量 會(huì)比 new 對(duì)象 形式效率高,但是在正則這里,好像不是這么回事,具體的請(qǐng)看下面的分析2020-04-04js正則表達(dá)式之RegExp對(duì)象屬性lastIndex,lastMatch,lastParen,lastContext,
js正則表達(dá)式之RegExp對(duì)象屬性lastIndex,lastMatch($&),lastParen($+),lastContext,rightContext屬性的講解2012-10-10