Various verifications of input input boxes

1. The input input box can only enter positive integer regular numbers ( i.e. >= zero and cannot be decimals )

<input type="text" value="1"
    onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"
    onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'0')}else{this.value=this.value.replace(/\D/g,'')}" />
// 大于等于 0 的正整数
<el-input v-model="searchForm.minPoint" placeholder="最小值" oninput = "value=value.replace(/[^\d]/g,'')"></el-input>

// 大于 0 的正整数
<el-input v-model="searchForm.minPoint" placeholder="最小值" @input="searchForm.minPoint=searchForm.minPoint.replace(/^(0+)|[^\d]+/g,'')"/>

 2. The input input box can only enter regular numbers (decimal points can be entered.)

<input onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')">
<input name="txt1" onchange="if(/\D/.test(this.value)){alert('只能输入数字');this.value='';}">

 3.input Enter positive numbers and decimals (reserve two digits)

<input  type="number" step="0.01"  min="0" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''">

 4.input input box for inputting pure numbers

<input type="text" name="" oninput="value=value.replace(/[^\d]/g,'')">

 5. The input input box can only enter numbers and defaults to 1 when the input is 0 (case: in the shopping cart)

<input type="text" value="1" onkeyup="value=(parseInt((value=value.replace(/\D/g,''))==''||parseInt((value=value.replace(/\D/g,''))==0)?'1':value,10))">

 6. Only letters and Chinese characters can be entered

<input onkeyup="value=value.replace(/[\d]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[\d]/g,''))" maxlength="10" name="Numbers">

 7. Only English letters and numbers can be entered, but Chinese characters cannot be entered.

<input onkeyup="value=value.replace(/[^\w\.\/]/ig,'')">

 8. Only numbers and English can be entered

<font color="Red">chun</font>
<input onkeyup="value=value.replace(/[^\d|chun]/g,'')">

 9. There can only be a maximum of two digits after the decimal point (both numbers and Chinese characters can be entered), letters and arithmetic symbols cannot be entered.

<input onkeypress="if((event.keyCode<48 || event.keyCode>57) &amp;&amp; event.keyCode!=46 || /\.\d\d$/.test(value))event.returnValue=false">

 10. There can only be up to two digits after the decimal point (numbers, letters, and Chinese can be entered), and arithmetic symbols can be entered.

<input onkeyup="this.value=this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3')">

 11. Enter Chinese, enter numbers, and enter English 

输入中文:
<input type="text" onkeyup="this.value=this.value.replace(/[^\u4e00-\u9fa5]/g,'')">
<br><br>
输入数字:
<input type="text" onkeyup="this.value=this.value.replace(/\D/g,'')">
<br><br>
输入英文:
<input type="text" onkeyup="this.value=this.value.replace(/[^a-zA-Z]/g,'')">
<br><br>
三个合在一起
<input onkeyup="value=value.replace(/[^\w\u4E00-\u9FA5]/g, '')">
<br><br>
只输入数字和字母:
<input class="input" maxlength="12" size="15" name="username" id="username" onkeyup="value=value.replace(/[\W]/g,'')">
<br><br>
除了英文的标点符号以为 其他的人都可以中文,英文字母,数字,中文标点
<input type="text" onkeyup="this.value=this.value.replace(/^[^!@#$%^&amp;*()-=+]/g,'')">

 12.  The input input box can only enter pure numbers and a maximum of 11 digits can be entered.

<input type="text" maxlength="11" oninput = "value=value.replace(/[^\d]/g,'')"  placeholder="请输入您的手机号">

Guess you like

Origin blog.csdn.net/cdd9527/article/details/130238020