Home  >  Article  >  Web Front-end  >  Can vue.js use regular expressions?

Can vue.js use regular expressions?

藏色散人
藏色散人Original
2021-01-05 09:37:352975browse

vue.js can use regular expressions, and its usage syntax is such as "this.taskInfo.amount = (money.match(/^(0|[1-9][0-9]*)/g )[0]) || null /^(0|[1-9][0-9]*)/g)[0]".

Can vue.js use regular expressions?

The operating environment of this tutorial: windows7 system , vue2.5.17 version, Dell G3 computer.

Related recommendations: "vue.js Tutorial"

Regular expressions can be used in vue.js.

Regular expression

1. Requirement: Only positive integers with 0 and non-0 switches can be entered

this.taskInfo.amount = (money.match(/^(0|[1-9][0-9]*)/g)[0]) || null
/^(0|[1-9][0-9]*)/g)[0]

2. Requirement: One decimal place is retained, and the first digit cannot be 0

this.taskInfo.money = (money.match(/^([1-9]*)(\.?\d{0,1})/g)[0]) || null
/^([1-9]*)(\.?\d{0,1})/g)[0]

3. A positive integer that cannot be zero is required

this.taskInfo.fbday = (fbday.match(/^([1-9]*)/g)[0]) || null
/^([1-9]*)/g)[0]

4. A regular expression to determine whether it 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
}

The above is the detailed content of Can vue.js use regular expressions?. 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