Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 141
  • Last Modified:

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
0
hjaycox
Asked:
hjaycox
  • 3
  • 2
1 Solution
 
RanaHossainCommented:
Public Function isValid() 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")

wrote and tested as vbs.. but should work in vb
0
 
RanaHossainCommented:
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")
0
 
BandyCommented:
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


0
 
RanaHossainCommented:
agreed... you need regular expression library.but the advantage is - as you said, it is very powerful.
0
 
BandyCommented:
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
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now