My code below loosely is per Zehra Nasif answer from Regular expression for matching latitude/longitude coordinates? (May 15 '14 at 20:00). While my code below is for MapServer, I think vanilla RE should work; the documentation says 'Google Regular Expression'! Here is my code:
VALIDATION
# '^[0-9]{5,8}$' # %parcelid% must be numeric and between 5 and 8 characters
'memberlong' "^-?[0-9]{1,3}(?:\.[0-9]{1,30})$" # -91.6666
'memberlat' "^[0-9]{1,3}(?:\.[0-9]{1,30})$" # 30.6666
'num_miles' "[0-9]+$" # 1200 works.
END
The first line is per the Mapserver document--that's just to illustrate their engine. And the num_miles
works when the input argument is 1200; that's also just to illustrate their engine. However, both memberlong
and memberlat
(or at least one of them--can't be sure because debug not pinpointing that) throw error msApplySubstitutions(): Regular expression error. Parameter pattern validation failed
and I think my regular expressions are not correct. I think, for now at least, it is safe to assume that memberlong (the longitudes) will be always negative and memberlat (the latitudes) will always be positive values, although for long term they should be able to handle negatives/positive. I just need to move on.
Any ideas?
Not all regex flavors support non-capturing groups, (?:...)
constructs. For example, POSIX ERE/BRE and XML Schema regex flavors only support capturing groups.
Moreover, in your case, you may simply remove the non-capturing groups as (?:xxx)
= xxx
. We only use non-capturing groups when we need to introduce alternations, or when we need to repeat a sequence of patterns with a quantifier.
So you need to use
'memberlong' "^-?[0-9]{1,3}\.[0-9]{1,30}$"
'memberlat' "^[0-9]{1,3}\.[0-9]{1,30}$"