web123456

el-input can only input integers, decimals, retain up to two decimals, and enter up to four decimals, filter special symbols in the el-input input box

Only positive integers can be entered in the input box. The input also prohibits the input of numericals starting with 0 to prevent it from being converted into other binary values.

<el-input
v-model=""
@input="(v)=>(=(/^(0+)|[^\d]+/g,''))"></el-input>
                  

1. Only pure numbers can be entered

<el-input v-model="aaa" type="text" @input="(v)=>(aaa=(/[^\d]/g,''))" />

2. Be able to enter pure numbers and decimals (for example: 6.66)

<el-input v-model="aaa" type="text" @input="(v)=>(aaa=(/[^\d.]/g,''))" />

3. Keep up to two decimal places (note: type="text")

<el-form-item label="train market price:" prop="trainMarketPrice">
   <el-input type="text" placeholder="Please enter content" v-model="" maxlength="20" onkeyup="value=(/[^\d.]/g, '')" show-word-limit>
   </el-input>
 </el-form-item>

 data() {

	 var marketPrice = (rule, value, callback) => {
       if ((String(value).length - (String(value).indexOf(".") + 1)) > 2 && String(value).indexOf(".") >= 0) {
             callback(new Error("training market price is limited to two decimal places"));
       } else {
           callback();
       }
     }
    
	 return {
		 form: {
			 trainMarketPrice: '',
		 }
		 rules:{
	         trainMarketPrice: [{ validator: marketPrice, trigger: 'blur'} ],
	 	 }
	 }
 }

Enter up to 4 decimal places

onkeyup="this.value=this.value.match(/\d+\.?\d{0,4}/);

<el-input placeholder="Please enter" onkeyup="=(/\d+\.?\d{0,4}/);" v-model="" clearable></el-input>
<el-input 
 v-model=""
 placeholder="Please enter"
 @input="limitInput($event)"
 ></el-input>
 >
//Limit only 4 decimal places to enter
limitInput (value) {
  this.increDistriNetForm.powerCapacity = ('' + value) // Step 1: Convert to string
    .replace(/[^\d^\.]+/g, '') // Step 2: Filter out what is not a number or a decimal point
    .replace(/^0+(\d)/, '$1') // Step 3: Starting from the first digit, and following 0 is a number, filter out and take the following number
    .replace(/^\./, '0.') // Step 4: If the first digit of input is a decimal point, replace it with 0. Implement automatic completion
    .match(/^\d*(\.?\d{0,4})/g)[0] || '' // Step 5: The final match is obtained. Start with a number, there is only one decimal point, and there can only be 0 to 2 decimal places after the decimal point.
},

4. Filter special symbols in the el-input input box

= (/[^\a-\z\A-\Z0-9\u4E00-\u9FA5]/g, "");

 // Note that you cannot add modifiers after v-model at this time. For example, the above command will be invalidated. The specific reasons are to be studied.

5. Only enter 0-9

onkeyup="value=(/^[^0-9]|[^\d]+/g,'')"

6. JS control cannot enter special characters

<input onkeyup="=(/[^u4e00-u9fa5w]/g,'')">;

7. JS controls the text box to enter only numbers

<input onkeyup="value=(/[^0-9]/g,'')" 
onpaste="value=(/[^0-9]/g,'')" 
oninput = "value=(/[^0-9]/g,'')">

8. JS controls the text box to enter only numbers and decimal points.

<input onkeyup="value=(/[^\0-9\.]/g,'')" 
onpaste="value=(/[^\0-9\.]/g,'')" 
oninput = "value=(/[^\0-9\.]/g,'')">

Control text boxes can only enter English

<input onkeyup="value=(/[^\a-\z\A-\Z]/g,'')" 
onpaste="value=(/[^\a-\z\A-\Z]/g,'')" 
oninput = "value=(/[^\a-\z\A-\Z]/g,'')">

Control text boxes can only enter English and numbers

<input onkeyup="value=(/[^\a-\z\A-\Z0-9]/g,'')" 
onpaste="value=(/[^\a-\z\A-\Z0-9]/g,'')" 
oninput = "value=(/[^\a-\z\A-\Z0-9]/g,'')">

Control text boxes can only enter Chinese

<input onkeyup="value=(/[^\u4E00-\u9FA5]/g,'')" 
onpaste="value=(/[^\u4E00-\u9FA5]/g,'')" 
oninput = "value=(/[^\u4E00-\u9FA5]/g,'')">

Control text boxes can only enter Chinese, English, and numbers

<input onkeyup="value=(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5]/g,'')" 
onpaste="value=(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5]/g,'')" 
oninput = "value=(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5]/g,'')">

Control text boxes can only enter Chinese, English, numbers, and spaces

<input onkeyup="value=(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\ ]/g,'')" 
onpaste="value=(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\ ]/g,'')" 
oninput = "value=(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\ ]/g,'')">

Control text boxes can only enter Chinese, English, numbers, and decimal points.

<input onkeyup="value=(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\.]/g,'')" 
onpaste="value=(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\.]/g,'')" 
oninput = "value=(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\.]/g,'')">