Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of input Box fixed input value format by regular expression

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains the "regular expression how to solve the problem of input box fixed input value format", the article explains the content is simple and clear, easy to learn and understand, now please follow Xiaobian's train of thought slowly in depth, together to study and learn "regular expression how to solve the input box fixed input value format problem" bar!

When using input for writing input, the following situations often occur:

You can only enter something. Chestnut: you can only enter numbers, only letters (uppercase, lowercase) can only be entered in a fixed format. Chestnut: you can only enter an amount, you can only enter a decimal number and a maximum of 2 digits can not be entered. Chestnut: you cannot enter special characters, such as "@ # ¥% & *".

In this case, it needs to be restricted directly on input, and regular expressions are mainly used to solve these problems in front-end applications.

The first case: you can only enter something

{{value}} export default {name: "app", data () {return {value:''} }, methods: {numCheck (val) {if (val! ='') {if (/ [^ 1-9] / .test (val)) {/ / drop ^ if you can't enter a number, / [1-9] / .test (val) / / can only enter letters, / [^ Amurz] / .test (val) / / can only enter letters or numbers (such as passwords) / [^ 1-9A-z] /) .test (val) this.$message ({type: "error", message: "only numbers can be entered, please re-enter!") this.value =''}

In the second case, you can only enter a fixed format.

Only two decimal places less than 1 can be entered

If (value > 1) {this.$message ({type: "error", message: "Please enter a number less than 1!"}) this.value =''return} if (! / ^ ([0-9] *) + (. [0-9] {1Magazine 2})? $/) .test (val) {this.$message ({type: "error", message: "Please enter two decimal places less than 1!"}) this.value =''}

Amount

If (value.length > 12) {this.$message ({type: "error", message: "length exceeds 12 Please re-enter "}) this.value =''return} if (! / / ^ [1-9] ([0-9] +)? (\. [0-9] {1 error})? $) | (^ (0) {1} $) | (^ [0-9]\. [0-9] ([0-9])? $) /) .test (value) {this.$message ({type:" error ", message:" only numbers can be entered. Please re-enter! "}) this.value =''}

In the third case, do not enter a

Var patrn = / [`~! @ # $% ^ & * _\-+ =? "{} |\;'\ [\] ~! @ # ¥%. & *-+ = {} |"? "[]',] / gim;if (patrn.test (val)) {this.$message ({type:" error ", message:" do not enter special characters! "})

Conclusion: it is very important to learn regular expressions!

Thank you for your reading, the above is the content of "regular expression how to solve the problem of fixed input value format in input box". After the study of this article, I believe you have a deeper understanding of how regular expression solves the problem of fixed input value format in input box. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report