Text Box 'character' Validation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Napalm
    New Member
    • Oct 2006
    • 8

    Text Box 'character' Validation

    Hi All,
    i'm new to posting in this forum , yet i have been lurking for a while.

    I was wondering if anyone has advice on how i can add a validation of a textbox .
    I'd like to set a min of 2 characters & a max of 50.
    I've searched around at previous posts & different sites , but i havent had a clar example
    Thanks in advance
    Napalm
  • Napalm
    New Member
    • Oct 2006
    • 8

    #2
    Hi,
    i've sorted this out . It was just a simple expression.

    however,
    if anyone could help me with an expression to detect if a user duplicates an input code ?.

    Thanks

    Comment

    • bharathreddy
      New Member
      • Aug 2006
      • 116

      #3
      Dear Napalm,

      If u want the validations to be done on the client side then:

      Note : textbox name = txtbox1
      submitbutton = btnSubmit


      Javascript function
      --------------------------:
      function validation1()
      {
      var txtbox1= document.getEle mentById('txtbo x1');

      if(txtbox1.leng th>2 && txtbox1.length< 50)
      {
      return true;
      }
      else
      {
      alert('Enter min 2 charts and max 50');
      return false;
      }

      }


      In html:

      <input type=button name=btnSubmit onclick='return validation1();' >

      summary: what happens is when a user enters less than 2 chars or more than 50 chars then error message will be displayed ("Enter min 2 charts and max 50'"). And the form is not posted in this case.

      Comment

      • Napalm
        New Member
        • Oct 2006
        • 8

        #4
        Thank bharathreddy
        i appreciate the info.
        napalm

        Comment

        • nmsreddi
          Contributor
          • Jul 2006
          • 366

          #5
          hello naplam

          can u post the solution that you found


          regards
          nmsreddi

          Comment

          • Napalm
            New Member
            • Oct 2006
            • 8

            #6
            This was the validation code that i was helped with.
            Thanks



            If Len(txtInputDes c.Text) > 1 And Len(txtInputDes c.Text) < 51 Then
            'All OK
            Else
            MsgBox("Please Enter A Description Between 2 and 50 characters")
            End If



            napalm

            Comment

            • nmsreddi
              Contributor
              • Jul 2006
              • 366

              #7
              Hello napalm

              this is the code in code behind have you not used any script becoz if you go for web application using c#.net you can't find msgbox ,i am looking for script for validating ,for my webapplication using c#.net


              any how many thanks for your reply

              thanks &regards

              nmsreddi

              Comment

              Working...