JS regular expressions are limited to 1-2 digit integers or contain at most two decimal places.

coldplay.xixi
Release: 2020-08-19 16:32:37
forward
6691 people have browsed it

JS regular expressions are limited to 1-2 digit integers or contain at most two decimal places.

【Related learning recommendations:js video tutorial

Test code

Copy after login

Rendering chart

If the two-digit integer is not limited, for example, at least 1-digit integer, [0-9]{1,} can be used

The regular expression in js is "| "

//必须以数字开头和数字结尾,中间可以包含 逗号,如果只有一个数字只能是数字 var regx1=/(^[0-9]{1,}[0-9,]{0,}[0-9]{1,}$)|(^[0-9]{1}$)/;
Copy after login

Regular expression table matches all two-digit numbers, and the tens digit is 1

For example, I want to match all characters in the form param_tag= 12. Such an equal sign is followed by two digits, and the tens digit is 1. You can use the following regular expression to match:

parma_tag=\<1[0-9]\> ;

Regular expression: matches two digits, and the first digit cannot be 0

^[1-9][0- 9]$

js regular, you can only enter numbers with at least two significant digits, and the number of digits can be up to five (the number of digits can be adjusted by yourself)

var reg=/^[1-9]\d{0,3}\.\d$|/^[1-9]\d{0,2}\.\d{2} $|^[1-9]\d{1,4}$|^[0]\.\d{2,4}$/;

Code analysis:

var reg = /^[1-9]\d{0,3}\.\d$/ ; //首位(1-9),中间零到三位数字,接着点号,点号后一位小数(0-9) var reg = /^[1-9]\d{0,2}\.\d{2}$/; //首位(1-9),中间零到二位数字,接着点号,点号后两位小数(0-9) var reg = /^[1-9]\d{1,4}$/; //首位(1-9),中间到结尾一到四位数字,无小数 var reg = /^[0]\.\d{2,4}$/; //首位(0),接着点号,点号后二到四位小数(0-9) //合并一起写则用'|'符号相连接,即为或的意思,满足任意一种条件都算符合
Copy after login

js regular expression - limit number length

For example: limit the number of words to 4

var reg = /^\d{4}$ /

Explanation: It starts with four numbers and ends with these four numbers, so the number length is limited to four.

Note: These four numbers are also used

Related recommendations:Programming video course

The above is the detailed content of JS regular expressions are limited to 1-2 digit integers or contain at most two decimal places.. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
js
source:jb51.net
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!