How to use 'remove all non-alphanumeric characters javascript' in JavaScript

Every line of 'remove all non-alphanumeric characters javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
1export function cleanAlphaNumericString(str: string): string {
2 return (str && typeof str === "string") ? str.replace(/\W/g, '') : str;
3}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

21function allowalphanumeric(e) {
22 var key = window.event ? e.keyCode : e.which;
23 var keychar = String.fromCharCode(key);
24 var reg = new RegExp("[a-zA-Z0-9]");
25 var carok = reg.test(keychar);
26 return carok;
27}

Related snippets