所以要么是9999999,要么是必需的医疗补助格式化字符串,返回一个值为True。
示例:
AZ12345Z NP54321J EM17345P
到目前为止,我有两个功能一起工作,但我弄乱了逻辑!!
谢谢
Public Function isAlpha(cChar As Integer) As Boolean
'returns true if its a alphabetic character
isAlpha = IIf((cChar >= 65 And cChar <= 90) Or (cChar >= 97 And cChar <= 122), True, False)
End Function
Public Function CheckMedicaidIDFormat(strMedicaidID As String) As Boolean
Dim blnResult As Boolean
If strMedicaidID = "99999999" or If Len(strMedicaidID) = 8 And isAlpha(Left(strMedicaidID, 2)) = True And IsNumeric(Mid(strMedicaidID, 3, 5)) = True And isAlpha(Right(strMedicaidID, 1)) = True Then
blnResult = True
Else
blnResult = False
End If
CheckMecicaidIDFormat = blnResult
End Function
发布于 2014-05-03 10:23:29
虽然RegEx
是解决这类问题的一个很好的通用解决方案,但是在本例中,简单的Like
比较就可以了。
Function IsValid(strIn As String) As Boolean
IsValid = (strIn Like "[A-Z][A-Z]#####[A-Z]") Or strIn = "99999999"
End Function
发布于 2014-05-03 05:31:16
就像这样
Sub Test()
MsgBox IsValid("AZ12345Z")
MsgBox IsValid("1AZ12345Z")
End Sub
测试功能
Function IsValid(strIn As String) As Boolean
If strIn = "99999999" Then
IsValid = True
Else
Dim objRegex As Object
Set objRegex = CreateObject("vbscript.regexp")
With objRegex
.Pattern = "^[A-Z]{2}\d{5}[A-Z]$"
IsValid = .Test(strIn)
End With
End If
End Function
发布于 2014-05-03 04:01:18
VBA支持使用COM VBScript.RegExp
对象的正则表达式,如下所示:
Dim regex As VBScript.RegExp
Set regex = New VBScript.RegExp ' or CreateObject("VBScript.RegExp")
regex.Pattern = "^[A-Za-z][A-Za-z]\d\d\d\d\d[A-Za-z]$"
If medicId = "99999999" Or regex.Test( medicId ) Then
' code to handle valid Medicaid ID here
End If
https://stackoverflow.com/questions/23440049
复制相似问题