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

coldplay.xixi
Release: 2020-11-12 16:37:55
Original
8893 people have browsed it

Vue.js method to determine whether the input is a number: Use regular expressions to determine whether the input value is a number. The code is [this.$message({type: 'warning',message: 'Please enter Number',duration: 10000})].

How vue.js determines whether the input is a number

【Recommended related articles: vue.js

vue.js method to determine whether the input is a number:

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
}
Copy after login

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

  • ^: represents the beginning of the regular expression ,

  • $ represents the end of the regular expression,

  • * represents matching 0-- Infinite,

  • [] represents the relationship between or

Related free learning recommendations: JavaScript(Video)

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template