Validation ----> Lock the text box without enabling to enter a single letter or a digit or a space or anything.
I just want to know that how do you do hard coding for validation of a text box. If it's a method or seperate function that would be easy for me. Then, it's easy for me to reuse that coding in the key press event of each text box.
Niradhip ChakrabortyRank #428 · 5.8K pointsPosted May 22, 2008, 8:44 AM EDT
Niradhip ChakrabortyRank #428 · 5.8K pointsPosted May 23, 2008, 10:02 AM EDT
You should call a javascript function in onclick or onkeypress event.
I will give you javascript function for the validation.
//To check whether a adress is proper email address or not.
function isEmail(s){
if (s.search(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/) == -1){
return false;
}
else{
return true;
}
}
//To check input is dizit or Character. This function will only allow user to enter number
function ValidatePhoneNo(Obj){
if(((window.event.keyCode >= 48) && (window.event.keyCode <= 57))){
var Value = Obj.value;
var len = Value.length;
if (len == 3 || len == 7 ){
Obj.value = Value + '-';
return true;
}
}
else{
alert("Phone No Cannot be a Character");
return false;
}
}
//the following function will disable a textbox call it in onload.My textbox id is txtVendorName
Function disable()
{
document.getElementById("txtVendorName").disable = true;
}
Dinusha Gamage47 pointsPosted May 25, 2008, 10:39 PM EDT
Dear Friend,
Thank you very much for your reply. But I need a small clarification about this coding. That is I jz want to know whether Javascript coding can be used in C # coding. Here, I'm developing a windows application, so... Can you apply these coding to validate text boxes in widows form?
Thanks in advance !
1 short reply
Dinusha Gamage47 pointsPosted May 22, 2008, 7:05 PM EDT
Yes. At client side.