hjaycox
asked on
code needed for serial number
I need code for registration of a prog. the code must match the following:
A = any letter from a to z
1 = any number from 1 to 0
Code needs to match the following format "AAA1A11AA1A1"
If code entered,does not match the format of
"AAA1A11AA1A1" then exit setup
A = any letter from a to z
1 = any number from 1 to 0
Code needs to match the following format "AAA1A11AA1A1"
If code entered,does not match the format of
"AAA1A11AA1A1" then exit setup
sorry, small mistake ---------
Public Function isValid(byVal stringV as string) as boolean
dim regEX as RegExp
set regEX = new RegExp
with regEX
.Pattern = "^[a-z]{3}\d[a-z]\d{2}[a-z ]{2}\d[a-z ]\d$"
.IgnoreCase = True
.Global = True
isValid = .Test(stringV)
end with
set regEX = nothing
end function
msgbox isValid("AAA1A11AA1A1a")
Public Function isValid(byVal stringV as string) as boolean
dim regEX as RegExp
set regEX = new RegExp
with regEX
.Pattern = "^[a-z]{3}\d[a-z]\d{2}[a-z
.IgnoreCase = True
.Global = True
isValid = .Test(stringV)
end with
set regEX = nothing
end function
msgbox isValid("AAA1A11AA1A1a")
Theoretically, yes, but I don't believe that Vb comes with the RegExp object, I think you need to download something to make VB support RegExp...
VB's "LIKE" function is not as powerful as full RegExp support, but you can do it...
'Note: Because of the "Ucase" statement, this
'function is NOT case sensitive. If you require
'case sensitive, remove the "UCASE" first.
'Note: "[A-Z]" matches any character
' "#" matches any digit
'Just combine the two into the pattern you want to match.
Public Function isValid(ByVal str As String) As Boolean
isValid = (UCase(str) Like "[A-Z][A-Z][A-Z]#[A-Z]##[A -Z][A-Z]#[ A-Z]#")
End Function
VB's "LIKE" function is not as powerful as full RegExp support, but you can do it...
'Note: Because of the "Ucase" statement, this
'function is NOT case sensitive. If you require
'case sensitive, remove the "UCASE" first.
'Note: "[A-Z]" matches any character
' "#" matches any digit
'Just combine the two into the pattern you want to match.
Public Function isValid(ByVal str As String) As Boolean
isValid = (UCase(str) Like "[A-Z][A-Z][A-Z]#[A-Z]##[A
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Seeing as everybody agrees regular expressions are more powerful, If you decide you want the Rexular Expression Library, you should be able to download it here:
http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/733/msdncompositedoc.xml
http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/733/msdncompositedoc.xml
dim regEX as RegExp
set regEX = new RegExp
with regEX
.Pattern = "^[a-z]{3}\d[a-z]\d{2}[a-z
.IgnoreCase = True
.Global = True
isValid = .Test(stringV)
end with
set regEX = nothing
end function
msgbox isValid("AAA1A11AA1A1a")
wrote and tested as vbs.. but should work in vb