Hi..
How to validate an ASP.Net Textbox using javascript.It should not accept Empty Textbox and even it should not accept if we enter spaces in front with empty text should also not allow.
Validations
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 25, 2012, 4:12 AM EDT
try...
Java script function
function validateWholeText(obj) {
if (document.getElementById(obj.id).value == "") {
alert('Empty text is not allowed.');
obj.focus();
}
}
function ValidateTextbox(ID, keyCode) {
if (document.getElementById(ID).value == "" && keyCode == 32) {
return false;
}
}
text box defination
this will not accept space as first digit and also not allow empty text on lost focus.
hope this will help you.
rakesh chaudhari57 reputationPosted Jul 25, 2012, 2:53 AM EDT
Hi Friend, Take this Validation function validate1() { var len = document.getElementById("TextBox1").value.length; if (event.keyCode == 32 && len == 0) { document.getElementById("TextBox1").value = ""; alert("Cannot start with a space"); return false; } else if ((event.keyCode > 96 && event.keyCode 64 && event.keyCode < 92) || event.keyCode == 32) { return true; } else { event.returnValue = false; return false; } } Hava A Happy Coding