jquery - Using Regex to allow disallow text -


i trying use regex limit characters alphabets , numbers

$('#textbox').on("keypress", function (e) {     var regex = new regexp("^[a-za-z0-9]+$");     // how proceed? }); 

however not sure how proceed now? how handle copy paste?

the input event should capture keys, pasting , other inputs etc. in newer browsers, , it's matter of replacing isn't aplhanumeric character or number in value.

i use /w, allows underscores , few other characters, filters out other characters aren't alphanumeric or numbers

$('#textbox').on("input", function (e) {     this.value = this.value.replace(/\w/g, ''); }); 

fiddle


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -