I would like to create my own plugin (without use any external libraries - it's for learning purpose) to validate text typed by user dynamically in regex test function.
In example I have regex pattern:
^.{2}$
And javascript function
$('#textbox').bind("keypress", function (event) {
var key = String.fromCharCode(!event.charCode ? event.which : event.charCode);
if (!regex.test(key)) {
event.preventDefault();
return false;
}
});
Now, I want to type two dots into textbox, but after first keypress is fired, one dot doesn't match to the pattern and nothing happens because event is prevented.
My question: Is it possible to check if currently typed text matches with regex pattern?