Skip to content

How do you define a method for text box validation?

Dinusha Gamage

Asked May 21, 2008, 11:15 PM EDT4 answers
Share
LinkedInX

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.

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Niradhip Chakraborty
    0
    Do you want the validation on client side or server side???
    0
  • Niradhip Chakraborty
    0

    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;
    }

    0
  • 0

    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 !

    0
  • 1 short reply
    • 0

      Yes. At client side.

      0