Micro Focus QTP (UFT) Forums
Validate Numeric value is displaying expected format - 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: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Validate Numeric value is displaying expected format (/Thread-Validate-Numeric-value-is-displaying-expected-format)



Validate Numeric value is displaying expected format - kalaivanan123 - 09-20-2013

My application displays the account number in specific format
(E.g :3782-924723-01008).

Can anyone suggest me how to validate that account number value is displaying in below format on my web application.

Format needs to validate : XXXX-XXXXXX-XXXXX


RE: Validate Numeric value is displaying expected format - ravi.gajul - 09-23-2013

use this regular expression [0-9]{4}-[0-9]{6}-[0-9]{5}
alternatively you may pass your account number to a function defined below
Code:
strAccountNumber="3782-924723-01008"

MsgBox(RegExpTest("[0-9]{4}-[0-9]{6}-[0-9]{5}", strAccountNumber))


Function RegExpTest(patrn, strng)
   Dim regEx, Match, Matches   ' Create variable.
   Set regEx = New RegExp   ' Create a regular expression.
   regEx.Pattern = patrn   ' Set pattern.
   regEx.IgnoreCase = True   ' Set case insensitivity.
   regEx.Global = True   ' Set global applicability.
   Set Matches = regEx.Execute(strng)   ' Execute search.
   For Each Match in Matches   ' Iterate Matches collection.
      RetStr = RetStr & "Match found at position "
      RetStr = RetStr & Match.FirstIndex & ". Match Value is '"
      RetStr = RetStr & Match.Value & "'." & vbCRLF
   Next
   RegExpTest = RetStr
End Function