📜  validar solo letras js - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:14.843000             🧑  作者: Mango

代码示例1
$("input.nombre").bind('keypress', function(event) {
  var regex = new RegExp("^[a-zA-Z ]+$");
  var key = String.fromCharCode(!event.charCode ? event.which : event.charCode);
  if (!regex.test(key)) {
    event.preventDefault();
    return false;
  }
});