Skip to content

Instantly share code, notes, and snippets.

@lnked
Created May 16, 2018 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lnked/44a8602553588ea5981b47098064bef7 to your computer and use it in GitHub Desktop.
Save lnked/44a8602553588ea5981b47098064bef7 to your computer and use it in GitHub Desktop.
handleKeypressName(e) {
const regexp = /[^A-Za-z -]/;
e = e || window.event;
const charCode = (typeof e.which == "number") ? e.which : e.keyCode;
const typedChar = String.fromCharCode(charCode);
const matched = !(regexp.test(typedChar));
if (!matched) {
e.preventDefault();
}
return matched;
},
handleInputName(e) {
const regex = /[^A-Za-z]/g;
if (regex.test(String.fromCharCode(e.keyCode)) && e.keyCode !== 32) {
e.preventDefault();
return !1;
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment