![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | RegEx to return False if input is invalid. This code needs to be able to know whether the InputBox is in the right format. If not the right format how do I have the RegEx determine it's a False value? The code works great when the right number format has been typed, but I can't get the last For Each Loop to work in my favor. The number format is 00-00-0000. '~~~~~~~~~~~~~~~~~~~~~~~~~~~Code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Option Explicit 'Declare our variable Dim objRegExpr, objMatch, objMatch1 Dim strNum 'Declare a variable to hold our collection of Matches Dim colMatches 'Create an instance of the regexp object Set objRegExpr = New regexp objRegExpr.Pattern = "[0-9]{2}-[0-9]{2}-[0-9]{4}" objRegExpr.Global = True objRegExpr.IgnoreCase = True 'InputBox for Job# strNum = InputBox("Type # of Job") 'Now, Execute the regular expression search Set colMatches = objRegExpr.Execute(strNum) MsgBox colMatches.Count & " matches found..." For Each objMatch in colMatches MsgBox objMatch.Value Next For Each objMatch1 in colMatches <> True MsgBox objMatch1.Value Next '~~~~~~~~~~~~~~~~~~~~~~~~~End~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Thanks, Matt |
My System Specs![]() |
| | #2 (permalink) |
| | Re: RegEx to return False if input is invalid. RemyMaza schrieb: Quote: > This code needs to be able to know whether the InputBox is in the > right format. If not the right format how do I have the RegEx > determine it's a False value? The code works great when the right > number format has been typed, but I can't get the last For Each Loop > to work in my favor. The number format is 00-00-0000. Assuming, the user should enter *one* Type code Quote: > objRegExpr.Pattern = "[0-9]{2}-[0-9]{2}-[0-9]{4}" anything before or after the Type code Quote: > objRegExpr.Global = True Quote: > objRegExpr.IgnoreCase = True [...] Quote: > 'Now, Execute the regular expression search get your boolean without further work [...] Quote: > For Each objMatch1 in colMatches <> True /interpreter for this new RemyMaza language. Use code like this Dim aTests : aTests = Array( _ "12-34-5678", "", " 00-00-0000 ", "12-3O-4321" _ ) Dim oRE : Set oRE = New RegExp oRE.Pattern = "^\d{2}-\d{2}-\d{4}$" Dim sTest For Each sTest In aTests WScript.StdOut.Write "sTest: |" & sTest & "| => " sTest = Trim( sTest ) If oRE.Test( sTest ) Then WScript.StdOut.WriteLine "good." Else WScript.StdOut.WriteLine "bad." End If Next output: RegExpDemo aufgerufen. sTest: |12-34-5678| => good. sTest: || => bad. sTest: | 00-00-0000 | => good. sTest: |12-3O-4321| => bad. done: 0 to see what I mean/experiement with RegExps. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| HELP! fileExist function always return 'FALSE' | VB Script | |||
| Re: how to capture "return $false" | PowerShell | |||
| Chinese Traditional Input using Phonetic Input | Vista General | |||
| Test-Path '' -IsValid does not return False but fails. Is this OK? | PowerShell | |||
| Weird [regex]::Matches return value | PowerShell | |||