Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to validate a series of 0s value

Community Beginner ,
Nov 13, 2013 Nov 13, 2013

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!

474
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 13, 2013 Nov 13, 2013

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)>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 13, 2013 Nov 13, 2013
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources