Jump to content

StringRegExp() Help


mdp716
 Share

Recommended Posts

Hello - I think StringRegExp() is going to give me a headace.

What I am looking to do is test a string which should match the following:

1.  Will always be 8 characters long

2.  Will always start with "P"

3.  2nd, 3rd, and 4th Characters will always be Alpha (from 'A' to 'Z')

4.  5th, 6th, 7th, and 8th Characters will always be hexidecimal (from '0' through '9' or 'A' to 'F')

The test string will already be all caps due to the Edit box style settings so no need to worry about lower case.

So basically, I am looking for an expression that will identify if the above rules are met in the tested string.

I know this should not be that hard, but I've spent a few hours on this already and haven't found the expression that will not allow errors to slip by.

Any one of you wizards out there have a quick answer to this?

Thanks in advance.

 

Link to comment
Share on other sites

I'm thinking something along the lines of StringRegExp($your_string, "^P[A-Z]{3}[0-9A-F]{4}$") should work...

Well that sure looks right - no doubt the problem is the solution was far simpler than I was thinking.  Will test it out tomorrow and let you know, thanks for this so much.

Link to comment
Share on other sites

No problem. :)

 

Just a parting shot: That regex precisely matches what you specified.  So for example, the first characters will fail on non-ASCII upper case letters (e.g. Ä).  It will also fail if you receive lower case hex characters.  Just so you know.

How's my riding? Dial 1-800-Wait-There

Trying to use a computer with McAfee installed is like trying to read a book at a rock concert.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...