Home > Web Front-end > HTML Tutorial > 正则表达式_html/css_WEB-ITnose

正则表达式_html/css_WEB-ITnose

WBOY
Release: 2016-06-21 08:47:29
Original
1150 people have browsed it

 var child = $("input[name='unit']").val();            var reg = /^[1-9][0-9]{0,}$/;            if (reg.test(child) != true) {                alert("请输入正确的数字");
Copy after login

哪里错了 我想输入一个 当是一位数字的时候数不为零或者多为数字的时候可以为非首位可以为零
正则表达式哪里错了


回复讨论(解决方案)

试下这个
^[1-9]\d*$

child 取值正确吗

child 取值正确吗

正确 而且 正则表达式 在网页上测试没问题

试下这个
^[1-9]\d*$

好的 试下

楼主的正则没错,首位非零数字也可以用零宽断言来判断

var reg = /(?=^[^0])\d+/;
Copy after login

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