3 examples of 'allow only alphanumeric in textbox using javascript' in JavaScript

Every line of 'allow only alphanumeric in textbox using 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
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}
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

4static invalidAlphaNumeric(control: Control):{ [key:string]:boolean } {
5 if ( control.value && control.value.length && !control.value.match(/^[a-z0-9]+$/i) ){
6 return {invalidAlphaNumeric: true };
7 }
8 return null;
9}
121function checkAllowedCharacters(query)
122{
123 matches = query.match(/[^a-zA-Z0-9_+\-:.()\"*?&|!{}\[\]\^~\\@#\/$%'= ]/);
124 if(matches != null && matches.length > 0)
125 {
126 if(alertUser) alert("Invalid search query! The allowed characters are a-z A-Z 0-9. _ + - : () \" & * ? | ! {} [ ] ^ ~ \\ @ = # % $ ' /. Please try again.")
127 return false;
128 }
129 return true;
130}

Related snippets