Link to home
Start Free TrialLog in
Avatar of Quack
QuackFlag for United States of America

asked on

is it possible to set up a regex to validate each position in a string of characters in a form field?

is it possible to set up a regex to validate each position in a string of characters in a form field?

I have a requirement for a contract number field in a Cold Fusion form. Requirements are:

•      Positions 1-6 will be the  70Z0XX where XX is the contracting office code IE: 23.
•      Positions 7-8 will be the two digit Fiscal Year IE: 17.
•      Position 9 will be the one character instrument code IE: C, D, F.
•      Positions 10-17 will be agency assigned number.
•      New Example: 70Z02317D00000001

Is it possible to set up an expression at different points w/in the string of characters? I've never done that...only length requirements and forcing it to start w/ either a number or a letter. thanks for any help.
Avatar of Bill Prew
Bill Prew

Assuming position 9 must be one of C, D or E, then this should work.  Take a look and give it a try, it validates that a field passes the test you outlined.  You can see it in action at this RegEx test site:

https://regex101.com/r/o2hdAc/1

^70Z0\d{4}[CDF]\d{8}$

Open in new window


»bp
Avatar of Quack

ASKER

thanks...it validates w/ my checker...I'll let you know...
Avatar of Quack

ASKER

looks as though this should work...thanks
Avatar of Quack

ASKER

Ok...I was wrong...the only validation is that it has to start w/ 70Z0...Z doesn't have to uppercase fyi and the rest of the string can be uppercase letters or numbers up to 22 characters. Would this work?

^[70Zz0][A-Za-z0-9]{1,21}$
I think you would want more like this.

^70[Zz]0[A-Za-z0-9]{1,22}$

Open in new window



»bp
Avatar of Quack

ASKER

Ok...back to the original requirments we go...sort of:

New requirements are:

•      Positions 1 – 4: ‘70Z0’ or ‘70z0’ where 0 is zero - good to go
•      Positions 5 – 6: alphanumeric
•      Positions 7 – 8: numeric
•      Position 9: alphabetic
•      Positions 10 – 17: alphanumeric

so would this work still?:

^70Z0\d{4}[CDF]\d{8}$

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Quack

ASKER

Sorry ... out of the country until yesterday...thanks so much for your help Bill!