Javascript Regex Only Textbox -
I was able to find solutions for this in C # / .net but not for regular web HTML. If there is already an answer then I will know and I will stop the question.
How to create a text box that will allow only a few characters (formerly alphanumeric) based on the given regex (eg [A-zA-Z0-9])? So if a user tries to enter anything else, then the paste is included, it has been removed or has not been allowed.
& lt; Input type = "text" class = "alphanumeric only" & gt;
The basic function will be:
string = String This will replace any character with the [a-ZA-Z0- 9] location (/ [^ a-zA-Z0- 9] / g, '') .
Now you can put it directly in your element declaration:
& lt; Input type = "text" class = "alphanumeric only" onkeyup = "this.value = this.value.replace (/ [^ a-zA-Z0- 9] / g, '')" & gt; or (as you use a class gesture) you can use this behavior as the class alphanumeric with every input element Along with:
var inputElems = document.getElemenstByTagName ("input"); For (var i = 0; i But it may be easier to do this or another JavaScript framework: < / P>
$ ("input.alphanumericOnly"). Bind ("key", function (e) {this.value = this.value.replace (/ [^ a-zA -Z0- 9] / G, '');});
Comments
Post a Comment