Let's take a look at the problem related to this javascript regular expression-php Tutorial

Source: Internet
Author: User
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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.