jQuery phone number validation allow spaces, minimum of 8 digits

余生长醉 提交于 2019-11-28 13:46:08

Remove the space before validating:

return this.optional(element) || /^\d{8,}$/.test(phone_number.replace(/\s/g, ''));

This way you retain the space

My suggestion is to just remove the spaces from the phone_number before validating.

jQuery.validator.addMethod(
  "phone",
  function(phone_number, element) {
    return this.optional(element) || /^\d{8}$/ *$/.test(phone_number.replace(/\s/g, ""));
  },
    "Please enter numbers only"
);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!