Only allow the input input box to enter numbers, javascript string non-empty verification

<el-input
    v-model.number="formInline.locally_target_power"
    onkeyup="if(isNaN(value))execCommand('undo')"
    :readonly="readonly">
</el-input>

The regular expression that restricts the input input box to only input numbers and decimal points: 

        οnkeyup="if(isNaN(value))execCommand('undo')"

trim() judges spaces

The trim() method is used to delete the leading and trailing blanks of the string, including blanks, tabs, newlines, and other blanks.

 const content = '           '         // 一列空格

 console.log(content.trim() === '')    // true

If the content is a number type, it needs to be converted to a string type, otherwise an error will be reported.

console.log(String(content).trim()  ===  '')         // true

Guess you like

Origin blog.csdn.net/CSDN_33901573/article/details/130623613