Jump to content
Sign in to follow this  
mdp716

StringRegExp() Help

Recommended Posts

mdp716

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.

 

Share this post


Link to post
Share on other sites
mrider

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

  • Like 1

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.

Share this post


Link to post
Share on other sites
mdp716

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.

Share this post


Link to post
Share on other sites
mdp716

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

That worked flawlessly - thank you so much for you help.

Share this post


Link to post
Share on other sites
mrider

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.

Share this post


Link to post
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
Sign in to follow this  

×