Home > Backend Development > PHP Tutorial > 大家帮忙看下,这个javascript正则的有关问题出在哪

大家帮忙看下,这个javascript正则的有关问题出在哪

WBOY
Release: 2016-06-13 10:05:19
Original
790 people have browsed it

大家帮忙看下,这个javascript正则的问题出在哪?
我把这段代码放在我自己的页面中测试,当用户名为1234567890sss时,循环测试,账号格式有时能通过,有时不能通过,而且这两种情况还交替进行,不知我的程序错在哪了?

JScript code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->if (!/([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/.test(cft_account))        {            var uin_len = cft_account.replace(/^\s+/g, "").replace(/\s+$/g, "").length;            var pre = /^[0-9]/gm;            if(!pre.test(cft_account.replace(/^0+/,"")))            {                alert("财付通账号格式不正确。");                alert(cft_account);                return false;            }            else if(uin_len != 10 && uin_len != 13)            {                alert("财付通账号格式不正确。(请输入10位或13位的账号)");                return false;            }        }
Copy after login

问题好像出在这个语句上
JScript code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->if(!pre.test(cft_account.replace(/^0+/,"")))
Copy after login


------解决方案--------------------
var pre = /^[0-9]/gm;

这个应该是:var pre = /^[1-9]/gm; 吧
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