Micro Focus QTP (UFT) Forums
validation code needed - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: validation code needed (/Thread-validation-code-needed)



validation code needed - nats - 06-02-2012

Hi,
I have a web edit text box which should not accept ^ and ~.Also the minimum characters that it should accept should be 3.
It should accept all alphanumeric characters except ^ and ~.

Please provide me the code for this in QTP.


RE: validation code needed - supputuri - 06-02-2012

Check if this is useful.

Code:
NegativeTest Dialog("Login").WinEdit("Agent Name:"),"^"
Public Function NegativeTest(objWebEdit,Input)
    If Input = " ~" Then
          'Logic to enter the data and validate the message
          objwebEdit.Set "~"
          msgbox "Input as ~"
    ElseIf Input = "^" Then
         'Logic to enter the data and validate the message
         objWebEdit.Set "^"
         msgbox "Input as ^"
    ElseIf Len(Input)<4 Then
         'Logic to enter the data and validate the message.
         objWebEdit.Set Input
         msgbox "Input less than 4 Charecters"
    Else
            msgbox "Please send the proper input."
    End If
End Function




RE: validation code needed - nats - 06-02-2012

Thankx for the reply.
Just wantd to know if it can be solved using regular expressions?
Also,this text box should not allow strings such as
anita^,~rohan.
Does the above code run successfuly for these examples too.?


RE: validation code needed - supputuri - 06-02-2012

Hi Nats,

Yes we can handle this using Regular expression too. You have to create a regular expression object and then create a pattern such that it will exclude the characters (~,^).

Yeah Script which I have provided will work for anita^,~rohan by using the instr function rather than doing direct validation for the characters. please find the below updated code.
Code:
NegativeTest Dialog("Login").WinEdit("Agent Name:"),"ani~ta"
Public Function NegativeTest(objWebEdit,Input)
    If Instr(Input, "~") >0 Then
          'Logic to enter the data and validate the message
          objwebEdit.Set Input
          msgbox "Input as " & Input
    ElseIf Instr(Input, "^") >0 Then
         'Logic to enter the data and validate the message
         objWebEdit.Set Input
         msgbox "Input as " & Input
    ElseIf Len(Input)<4 Then
         'Logic to enter the data and validate the message.
         objWebEdit.Set Input
         msgbox "Input less than 4 Charecters"
    Else
            msgbox "Please send the proper input."
    End If
End Function



RE: validation code needed - nats - 06-16-2012

Hey thanx a llot!!Wink


RE: validation code needed - Ankur - 06-16-2012

@nats: Please make sure to read the posting guidelines and post on appropriate sub-forum.