javascript checkValidity

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript checkValidity相关的知识,希望对你有一定的参考价值。

var emailField = document.getElementById("some_id");
emailField.addEventListener('keyup', function (event) {
    isValidEmail = emailField.checkValidity();
  }
);

// regex

var patt = /[\S]+@[a-zA-Z0-9.]+?\.[a-zA-Z]{1,12}/;
if(!patt.test(url_params["email"]))
{
  //bad format
}
  /*  EventListeners */
  nameField.addEventListener("keyup", function(event) {
    // fix: no auto in/valid css / force on input empty
    if(nameField.value == "")
      nameField.setCustomValidity("false")
    else
      nameField.setCustomValidity("");
  });
    // validate
    el = document.getElementById("errorNoticeBox");
    el.innerHTML = "";
    if(url_params["name"].length == 0)
    {
      el.innerHTML += "Name field must not be empty!<br>"
      nameField.setCustomValidity("false");
      return false;
    }else{
      nameField.setCustomValidity("");
    }
    
    if(url_params["email"].length == 0)
    {
      el.innerHTML += "Email field must not be empty!<br>"
      return false;
    }

以上是关于javascript checkValidity的主要内容,如果未能解决你的问题,请参考以下文章

JavaScript 验证 API中的setCustomValidity()方法

MFC 旋转/编辑控件

如何验证文本区域中的模式匹配?

jquery使用案例

C#ext从后面的代码更改按钮的图标

信用卡验证 - 带有空格的匹配模式