Validate Textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AishaKhalfan
    New Member
    • Apr 2007
    • 23

    Validate Textbox

    Hi All,


    I have a textbox that should be validated to enter letters only. However, if the users enter number it should be given error message. This application is windows application.


    Any volunteer to help me to solve this particularly problem.


    I’m looking forward to answering this post.


    Thanks & Regards,

    Aisha
  • gomzi
    Contributor
    • Mar 2007
    • 304

    #2
    Originally posted by AishaKhalfan
    Hi All,


    I have a textbox that should be validated to enter letters only. However, if the users enter number it should be given error message. This application is windows application.


    Any volunteer to help me to solve this particularly problem.


    I’m looking forward to answering this post.


    Thanks & Regards,


    Aisha
    try out -> regex.ismatch(y ourstring,"^([a-z])*$")

    Comment

    • AishaKhalfan
      New Member
      • Apr 2007
      • 23

      #3
      Originally posted by gomzi
      try out -> regex.ismatch(y ourstring,"^([a-z])*$")

      Where should I place this code?




      Thanks & Regards,

      Aisha

      Comment

      • gomzi
        Contributor
        • Mar 2007
        • 304

        #4
        Originally posted by AishaKhalfan
        Where should I place this code?




        Thanks & Regards,

        Aisha
        inside the event of your form submit button.

        Comment

        • AishaKhalfan
          New Member
          • Apr 2007
          • 23

          #5
          What is the data type of regex because I have to declare?



          Thanks & Regards,

          Aisha

          Comment

          • gomzi
            Contributor
            • Mar 2007
            • 304

            #6
            Originally posted by AishaKhalfan
            What is the data type of regex because I have to declare?



            Thanks & Regards,

            Aisha
            There is no need for declaring it.
            You will be using its static method "IsMatch()"

            Comment

            • AishaKhalfan
              New Member
              • Apr 2007
              • 23

              #7
              I got error that telling me regex not declared. I placed the code in save button as following:


              regex.ismatch(t xtemployeeName, "^([a-z])*$")


              Should I need to important any ting?



              Thanks & Regards,

              Aisha

              Comment

              • gomzi
                Contributor
                • Mar 2007
                • 304

                #8
                Originally posted by AishaKhalfan
                I got error that telling me regex not declared. I placed the code in save button as following:


                regex.ismatch(t xtemployeeName, "^([a-z])*$")


                Should I need to important any ting?



                Thanks & Regards,

                Aisha
                try importing system.text and system.text.reg ularexpressions

                Comment

                • krknaveen
                  New Member
                  • Nov 2006
                  • 7

                  #9
                  Hi Aisha,

                  The Most simple way of doing it is to trap the ASCII value in the hey press event of the textbox and validate the character.

                  The Following is asample code for not allowing any values except a-z and A-Z

                  Private Sub TextBoxKeyPress (ByVal sender As System.Object, ByVal e As System.Windows. Forms.KeyPressE ventArgs) _
                  Handles TextBoxName.Key Press
                  Select Case Asc(e.KeyChar)
                  Case 97 To 122, 65 To 90
                  Case Else
                  e.Handled = True
                  End Select
                  End Sub

                  Hope this will solve your purpose.

                  Regards,
                  Naveen

                  Comment

                  • krknaveen
                    New Member
                    • Nov 2006
                    • 7

                    #10
                    Hi Aisha,

                    48-57 is the ASCII range for 0-9

                    Instead of e.Handled, give the message in the message box.

                    Regards,
                    Naveen

                    Comment

                    • AishaKhalfan
                      New Member
                      • Apr 2007
                      • 23

                      #11
                      Hi Naveen


                      First, I would like to thank you for helping me to solve this problem a lot.

                      Case 97 To 122, 65 To 90

                      Could explain for me this line please?



                      You supporting is appreciated


                      Thanks & Regards,

                      Aisha
                      .

                      Comment

                      Working...