Home >Web Front-end >Vue.js >How vue.js determines whether the input is a number

How vue.js determines whether the input is a number

藏色散人
藏色散人Original
2020-12-16 10:45:269162browse

vue.js method to determine whether the input is a number: first create a front-end sample file; then use the regular expression "var numReg=/^[0-9]*$/" in vue to determine the input Whether the value is a number is sufficient.

How vue.js determines whether the input is a number

The operating environment of this tutorial: windows7 system, vue version 2.0. This method is suitable for all brands of computers.

Related recommendations: "vue.js Tutorial"

Regular expressions can be used in vue to determine whether the input value is a number:

var numReg = /^[0-9]*$/
var numRe = new RegExp(numReg)
if (!numRe.test(number)) {
  this.$message({
    type: 'warning',
    message: '请输入数字 ',
    duration: 10000,
    showClose: true,
  })
  return false
}

Regular expression /^[0-9]*$/ means that only numbers can be entered:

^: represents the beginning of the regular expression,

$ represents the regular expression End,

* represents matching 0--infinite,

[] represents the relationship of or

The above is the detailed content of How vue.js determines whether the input is a number. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn