Reputation: 364
I would like to check if the provided string contains a number with more than ten digits.
exampleString = aaa123aaa12345aaaa <--- not true
exampleString = 12345678 <--- not true
exampleString = 1234567,12345,123345 <--- not true
exampleString = aaaa12345678901234aaaa124aaa <-- true
I was trying to do something like extracting numbers to individual strings and then check if their length > 10, but I was unsuccesfull.
Any help or suggestions?
Upvotes: 0
Views: 599
Reputation: 33692
Using RegEx
object:
Option Explicit
Sub TestReg()
' sub to test RegEx10Digits function
Dim exampleString As String
exampleString = "aaaa12345678901234aaaa124aaa"
MsgBox RegEx10Digits(exampleString)
End Sub
Function RegEx10Digits(RegString As String) As Boolean
' RegEx variables
Dim Reg As Object
Dim RegMatches As Variant
RegEx10Digits = False
Set Reg = CreateObject("VBScript.RegExp")
With Reg
.Global = True
.IgnoreCase = True
.Pattern = "\d{11,}" ' Match any set of 10+ digits
End With
Set RegMatches = Reg.Execute(RegString)
If RegMatches.Count >= 1 Then ' make sure there is at least 1 match
RegEx10Digits = True
End If
End Function
Upvotes: 0
Reputation: 7152
Function IsMore10Digits(strVal)
With CreateObject("VBScript.RegExp")
.Pattern = "\d{11,}": IsMore10Digits = .Test(strVal)
End With
End Function
Upvotes: 1