怎么實現(xiàn)一個只能輸入正整數(shù)的正則表達式?針對這個問題,這篇文章詳細介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
創(chuàng)新互聯(lián)2013年開創(chuàng)至今,先為瑪納斯等服務(wù)建站,瑪納斯等地企業(yè),進行企業(yè)商務(wù)咨詢服務(wù)。為瑪納斯企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。<input type='text' id='SYS_PAGE_JumpPage' name='SYS_PAGE_JumpPage' size='3' maxlength='5' onkeyup='this.value=this.value.replace(/[^1-9]/D*$/,"")' ondragenter="return false" onpaste="return !clipboardData.getData('text').match(//D/)"" >
1.只能輸入數(shù)字和英文的:
<input onkeyup="value=value.replace(/[/W]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))" ID="Text1" NAME="Text1">
2.只能輸入數(shù)字的:
<input onkeyup="value=value.replace(/[^/d]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))" ID="Text2" NAME="Text2">
3.只能輸入全角的:
<input onkeyup="value=value.replace(/[^/uFF00-/uFFFF]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/uFF00-/uFFFF]/g,''))" ID="Text3" NAME="Text3">
4.只能輸入漢字的:
<input onkeyup="value=value.replace(/[^/u4E00-/u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/u4E00-/u9FA5]/g,''))" ID="Text4" NAME="Text4">
5.郵件地址驗證:
var regu = "^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2}|net|NET|com|COM|gov|GOV|mil|MIL|org|ORG|edu|EDU|int|INT)$" var re = new RegExp(regu); if (s.search(re) != -1) { return true; } else { window.alert ("請輸入有效合法的E-mail地址 !") return false; }
6.身份證:
"^//d{17}(//d|x)$"
7.17種正則表達式
"^//d+$" //非負整數(shù)(正整數(shù) + 0) "^[0-9]*[1-9][0-9]*$" //正整數(shù) "^((-//d+)|(0+))$" //非正整數(shù)(負整數(shù) + 0) "^-[0-9]*[1-9][0-9]*$" //負整數(shù) "^-?//d+$" //整數(shù) "^//d+(//.//d+)?$" //非負浮點數(shù)(正浮點數(shù) + 0) "^(([0-9]+//.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*//.[0-9]+)|([0-9]*[1-9][0-9]*))$" //正浮點數(shù) "^((-//d+(//.//d+)?)|(0+(//.0+)?))$" //非正浮點數(shù)(負浮點數(shù) + 0) "^(-(([0-9]+//.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*//.[0-9]+)|([0-9]*[1-9][0-9]*)))$" //負浮點數(shù) "^(-?//d+)(//.//d+)?$" //浮點數(shù) "^[A-Za-z]+$" //由26個英文字母組成的字符串 "^[A-Z]+$" //由26個英文字母的大寫組成的字符串 "^[a-z]+$" //由26個英文字母的小寫組成的字符串 "^[A-Za-z0-9]+$" //由數(shù)字和26個英文字母組成的字符串 "^//w+$" //由數(shù)字、26個英文字母或者下劃線組成的字符串 "^[//w-]+(//.[//w-]+)*@[//w-]+(//.[//w-]+)+$" //email地址 "^[a-zA-z]+://(//w+(-//w+)*)(//.(//w+(-//w+)*))*(//?//S*)?$" //url
=============================================
1.取消按鈕按下時的虛線框
在input里添加屬性值 hideFocus 或者 HideFocus=true
2.只讀文本框內(nèi)容
在input里添加屬性值 readonly
3.防止退后清空的TEXT文檔(可把style內(nèi)容做做為類引用)
<INPUT style=behavior:url(#default#savehistory); type=text id=oPersistInput>
4.ENTER鍵可以讓光標移到下一個輸入框
<input onkeydown="if(event.keyCode==13)event.keyCode=9" >
5.只能為中文(有閃動)
<input onkeyup="value="/value.replace(/[" -~]/g,'')" onkeydown="if(event.keyCode==13)event.keyCode=9">
6.只能為數(shù)字(有閃動)
<input onkeyup="value="/value.replace(/["^/d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))">
7.只能為數(shù)字(無閃動)
<input ime-mode:disabled" onkeydown="if(event.keyCode==13)event.keyCode=9" onKeyPress="if ((event.keyCode<48 || event.keyCode>57)) event.returnValue=false">
8.只能輸入英文和數(shù)字(有閃動)
<input onkeyup="value="/value.replace(/[/W]/g,"'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))">
9.屏蔽輸入法
<input type="text" name="url" ime-mode:disabled" onkeydown="if(event.keyCode==13)event.keyCode=9">
10. 只能輸入 數(shù)字,小數(shù)點,減號(-) 字符(無閃動)
<input onKeyPress="if (event.keyCode!=46 && event.keyCode!=45 && (event.keyCode<48 || event.keyCode>57)) event.returnValue=false">
11. 只能輸入兩位小數(shù),三位小數(shù)(有閃動)
<input maxlength=9 onkeyup="if(value.match(/^/d{3}$/))value="/value.replace(value,parseInt(value/10))" ;value="/value.replace(//./d*/./g,'."')" onKeyPress="if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46 && event.keyCode!=45 || value.match(/^/d{3}$/) || //./d{3}$/.test(value)) {event.returnValue=false}" id=text_kfxe name=text_kfxe>
關(guān)于怎么實現(xiàn)一個只能輸入正整數(shù)的正則表達式問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識。
網(wǎng)站題目:怎么實現(xiàn)一個只能輸入正整數(shù)的正則表達式-創(chuàng)新互聯(lián)
網(wǎng)站網(wǎng)址:http://bm7419.com/article42/cdehec.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動網(wǎng)站建設(shè)、Google、網(wǎng)站排名、網(wǎng)頁設(shè)計公司、微信小程序、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容