1
Answer

How to allow alphanumeric in txtbox using javascript in.net?

Raja

Raja

7y
226
1
I have one textbox thats allow alphanumeric if user enters symbols show the alert message
'You have enter symbol do you want to continue'
 'yes/no
 
If click yes symbol is allowed.if click no symbol is not allowed. 
Answers (1)
1
Ravi Kumar

Ravi Kumar

NA 348 31.4k 7y
Go with regular Expression it might be helpful
  1. $('#text').keypress(function (e) {    
  2.     var regex = new RegExp("^[a-zA-Z0-9]+$");    
  3.     var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);    
  4.     if (regex.test(str)) {    
  5.         return true;    
  6.     }    
  7.     e.preventDefault();    
  8.     return false;    
  9. });