I know what you mean, and I did something like that in my code that I
backported from 3.5.x to 3.4.x. I added another regex field that said
whether something was mandatory or not, where 1 is mandatory, and 0 is
not:
(?#Year)(?#0)[1]\d{3}$ year, not mandatory
(?#Mandatory)(?#1). anything, mandatory
(?#postal code)(?#1)[2]{2}$ postal code, mandatory
The second one is useful for a field where you want anything, don’t care
how long or what it looks like, so long is it isn’t left blank.
Obviously, I hacked on the RT code a little that reads this stuff to
accomodate for the second regex group.
Eric Schultz
United Online
[mailto:rt-users-bounces@lists.bestpractical.com] On Behalf Of Todd
ChapmanSent: Friday, June 23, 2006 2:56 PM
To: Nick Metrowsky
Cc: rt-users@lists.bestpractical.com
Subject: Re: [rt-users] Regular Expressions for Custom Field Validation
in RT3.6.0
Hi Everyone,
Once I was told where Custom Field Validation is maintained in RT
3.6.0,
I thought I make this small contribution to RT 3.6.0. The following
code
snippet contains several useful regexp validations. Two of these are
provided with RT 3.6.0 (Mandatory, Digits), the new additions are as
follows:
- DateYYYYMMDD - Date in YYYY-MM-DD or YYYY/MM/DD format
- DateMMDDYYYY - Date in MM-DD-YYYY or MM/DD/YYYY format
- DateDDMMYYYY - Date in DD-MM-YYYY or DD/MM/YYYY format
- Float - Floating Point Numbers
- Email - Email address format
- IPAddress - IP Address format
- USZipCode5 - US 5 digit Zip Code
- UZZipCode9 - US 9 digit Zip Code
- USZipCode5or9 - US Zip Code (either 5 digit or 9 digit)
- USTelephone - US Telephone Numbers
- RowRackHeight - Something used by us locally for locating
equipment in out data center; Row #, Rack #, and Unit Height # in
Rack.
Nick,
I submitted a patch to Jesse that implements a callback
so that new validations can be easily added. Hopefully the
patch will make it into 3.6.1.
Also, for every validation it would be useful to have
another validation that makes it possible to insert
no data.
For example:
(?#Date)^\d\d\d\d-\d\d-\d\d$
(?#Optional Date)^(\d\d\d\d-\d\d-\d\d)?$
The first requires a date. The second allows a blank
CF, but a date is entered it has to match the format.
-Todd