Problems encountered in js cycle form value and matching check configuration

clipboard.png
problem description:
first click submit:
Mobile check-> normal-> enter the next code value check-> return false termination;
second click submit:
Mobile check-> return false termination;
3Jing 4 Click to submit 1Magne2

as shown in the picture, who knows what caused it?

< hr >

the following is the reference code

/**
 * 
 * formData: {key:value}
 */
function checkForm(formData) {
  console.log(formData)
  for (let item in formData) {
    let info = formData[item];
    let reg = VERIFYCONFIG[item] ? VERIFYCONFIG[item].reg : null;
    if (reg){
      let isValid = reg.test(info);
      console.log(item, reg, info, isValid)
      if (!isValid) {
        wx.showToast({
          title: VERIFYCONFIG[item].title + "!",
          icon: "none"
        })
        return false
      }
    }
  }
  return true
}

/**
 * 
 * key key
 * reg nullkey
 */
const VERIFYCONFIG = {
  mobile: {
    title: "",
    reg: /^1(2|3|4|5|6|7|8|9)[0-9]{9}$/g,
  },

  code: {
    title: "",
    reg: /\d{4,}/g
  },

  pwd: {
    title: "",
    reg: /\S{6,}/g
  },

  inverterCode: {
    reg: /\w*/g
  },

  name: {
    title: "",
    reg: /\S+/g
  },

  address: {
    title: "",
    reg: /\S+/g
  },

}
Nov.02,2021

because you are literally regular, you set

after each check.
reg.lastIndex = 0

is fine.
the exec method, and the test method both make the index move

Menu