Copy link to clipboard
Copied
I'm trying validate values such as 0 or 00 or 000 or 0000, or 000000 up to 10 digits.
I can use <cfif varId IS "0" OR varId IS "00" OR varId IS "000" etc> but I believed there should be a better and more elegant way to do this.
I need to reject anyone of these value from entering my database table.
Can anyone help?
Thank you!
Copy link to clipboard
Copied
use a regular expression.
<cfif reFind("^0{1,10}$", varId)>
There might be an issue here though, I can't remember if ColdFusion allows for 2-digit values in the { } quantifier part of that (not everywhere can deal with it, and Adobe CF's regex engine is old enough that I doubt it will manage).
If you don't really care about the length (e.g. theoretically an 11 digit string of zeros is also invalid), then you could also just do:
<cfif reFind("^0+$", varId)>
Copy link to clipboard
Copied
I just confirmed that the first expression @duncancumming provided will work on CF 9.0.2. It validates strings containing 1-10 zeroes, but fails on 11 or more zeroes, as intended.
-Carl V.