我是新来的正则表达式,我试图用正则表达式验证数据库中的收据号码。7位数字后跟可选3个字母的正则表达式
我们的收入就可以派上以下格式:
- (Manditory七个数字,没有更多,不会少)
- 0126456a(Manditory七个数字一个字母AZ)
- 0126456ab(Manditory七位数以两个字母AZ)
- 0126456abc(Manditory七个数字用三个字母AZ)
我试过使用一堆不同的正则表达式组合,但似乎没有任何工作。现在我有:
(\d)(\d)(\d)(\d)(\d)(\d)(\d)([a-z])?([a-z])?([a-z])?
但是,这是允许超过七位数字,并允许超过3个字母。
这是Access 2010中内我的VBA功能,将验证表达式:
Function ValidateReceiptNumber(ByVal sReceipt As String) As Boolean
If (Len(sReceipt) = 0) Then
ValidateReceiptNumber = False
Exit Function
End If
Dim oRegularExpression As RegExp
' Sets the regular expression object
Set oRegularExpression = New RegExp
With oRegularExpression
' Sets the regular expression pattern
.Pattern = "(\d)(\d)(\d)(\d)(\d)(\d)(\d)([a-z])?([a-z])?([a-z])?"
' Ignores case
.IgnoreCase = True
' Test Receipt string
ValidateReceiptNumber = .Test(sReceipt)
End With
End Function