Hello, is there any way to execute validating event handler statements for textbox while the user is typing instead of after textbox loses focus?
Loading
Hello, is there any way to execute validating event handler statements for textbox while the user is typing instead of after textbox loses focus?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Oct 15, 2022, 11:58 AM EDT
I just used the Text change or keypress or keydown or preview... event
Sachin SinghRank #66 · 26.2K reputationPosted Oct 15, 2022, 4:21 PM EDT
What do you mean by "Validating event handler"?
If you want to do something while user is typing you can use Change(),KeyPress() or KeyDown() or KeyUp() events.
$("#txtDemo").Keydown(function(event) { var charTyped=event.Which; if(charTyped==32) // for example:- if you don't want to allow spaces { return; } else{ // call another method or do nothing; } });Jignesh KumarRank #91 · 22.9K reputationPosted Oct 16, 2022, 12:39 AM EDT
Hi Ajay,
You can use keypress event which will help you to restric user while typing,
$(function () { $("#txtName").keypress(function (e) { var keyCode = e.keyCode || e.which; $("#lblError").html(""); var regex = /^[0-9]+$/; var isValid = regex.test(String.fromCharCode(keyCode)); if (!isValid) { $("#lblError").html("Only Numbers allowed."); } return isValid; }); });Naresh BeniwalRank #365 · 6.8K reputationPosted Oct 30, 2022, 12:59 PM EDT
https://www.codeproject.com/Questions/1278768/How-do-I-validate-user-entry-in-a-textbox-in-the-l