How to disable pasting special characters in text box?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PrateekArora
    New Member
    • Feb 2007
    • 7

    How to disable pasting special characters in text box?

    Hi guys...

    I am using a text box in vb6 application and I have applied validations on it such that it will only accept Numeric data through keyboard.
    But the problem is when I try to paste some special characters in it through Mouse Right Click, it gets pasted from clip board.
    It happens because I have applied validations on Keypress event.
    Let me tell u that CTRL+V (paste through keyboard is also disabled).
    Now what I want is either I should trap the Mouse right click event and check if "Paste" option is selected, if it is true then I can use "isnumeric(Clip board.GetText() )" and read data from clipboard and prompt a message that non numeric data present on clip board.
    If button = vbRightclick then
  • vijaydiwakar
    Contributor
    • Feb 2007
    • 579

    #2
    Originally posted by PrateekArora
    Hi guys...

    I am using a text box in vb6 application and I have applied validations on it such that it will only accept Numeric data through keyboard.
    But the problem is when I try to paste some special characters in it through Mouse Right Click, it gets pasted from clip board.
    It happens because I have applied validations on Keypress event.
    Let me tell u that CTRL+V (paste through keyboard is also disabled).
    Now what I want is either I should trap the Mouse right click event and check if "Paste" option is selected, if it is true then I can use "isnumeric(Clip board.GetText() )" and read data from clipboard and prompt a message that non numeric data present on clip board.
    If button = vbRightclick then
    just lock the textbox in keydown event txt have the property use it

    Comment

    • PrateekArora
      New Member
      • Feb 2007
      • 7

      #3
      thnx dude I tried same but I need to enter numeric data through keyboard, if we will lock text box it will create problem.
      what I thought is to trap the default menu editor and check if the menu item selected is "Paste", if true then we can check data on clipboard if it is numeric then proceed else show msg of invalid data on clip board.
      In this implementation I m having problem that I m not able to trap default menu editor and the click of "Paste " option.
      can u suggest anything in this respect...

      Comment

      • vijaydiwakar
        Contributor
        • Feb 2007
        • 579

        #4
        Originally posted by PrateekArora
        thnx dude I tried same but I need to enter numeric data through keyboard, if we will lock text box it will create problem.
        what I thought is to trap the default menu editor and check if the menu item selected is "Paste", if true then we can check data on clipboard if it is numeric then proceed else show msg of invalid data on clip board.
        In this implementation I m having problem that I m not able to trap default menu editor and the click of "Paste " option.
        can u suggest anything in this respect...
        See I'll give u d code tommoro b'coz it's my time to go home so tomoro when i will come i'll give u d code
        Trust me
        both Ctrl+V and menu Paste will be get disabled
        Trust me

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          You could try a simple brute-force approach. In the Change event, just go through the .Text property and remove any non-numeric characters.

          Comment

          • vijaydiwakar
            Contributor
            • Feb 2007
            • 579

            #6
            Originally posted by PrateekArora
            Hi guys...

            I am using a text box in vb6 application and I have applied validations on it such that it will only accept Numeric data through keyboard.
            But the problem is when I try to paste some special characters in it through Mouse Right Click, it gets pasted from clip board.
            It happens because I have applied validations on Keypress event.
            Let me tell u that CTRL+V (paste through keyboard is also disabled).
            Now what I want is either I should trap the Mouse right click event and check if "Paste" option is selected, if it is true then I can use "isnumeric(Clip board.GetText() )" and read data from clipboard and prompt a message that non numeric data present on clip board.
            If button = vbRightclick then
            dear i'm with d sol. just try it
            Code:
            Private Sub Text1_KeyPress(KeyAscii As Integer)
                CheckCopyPaste Text1, KeyAscii
            End Sub
            
            Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
                CheckCopyPaste Text1, Button
            End Sub
            
            Public Sub CheckCopyPaste(txtbox As Object, KeyCode As Integer)
                If KeyCode <> 22 And KeyCode <> 93 And KeyCode <> 2 Then
                    txtbox.Locked = False
                Else
                    txtbox.Locked = True
                End If
            End Sub

            Comment

            • ChillUmesh
              New Member
              • Feb 2007
              • 20

              #7
              Can u not use richtext box tool

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #8
                Originally posted by ChillUmesh
                Can u not use richtext box tool
                While we're on the subject, what about the Masked Edit control?

                Comment

                Working...