Let's take a look at the problem with this javascript regular expression? I put this code in my own page for testing. when the user name is 1234567890sss, the loop test is conducted. the account format can sometimes pass, sometimes fail, and the two situations are also alternating, I don't know where my program is wrong? JScriptcodeif (! ([W-.] +) @ ([0-9] {1, 3 }. [0-9] {1, 3 }. [0-9] {1, 3. What is the problem with this javascript regular expression?
I put this code in my own page for testing. when the user name is 1234567890sss, the loop test is conducted. the account format can sometimes pass, sometimes fail, and the two situations are also alternating, I don't know where my program is wrong?
JScript code
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 ("Caifu Tong account format is incorrect. "); Alert (cft_account); return false;} else if (uin_len! = 10 & uin_len! = 13) {alert ("The final payment account format is incorrect. (Enter a 10-or 13-digit account) "); return false ;}}
The problem seems to be caused by this statement.
JScript code
if(!pre.test(cft_account.replace(/^0+/,"")))
------ Solution --------------------
Var pre =/^ [0-9]/gm;
This should be: var pre =/^ [1-9]/gm;