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

simple regex validation

Guest
May 16, 2008 May 16, 2008
I need to match any number up to a 3 digits (e.g., 0 -> 999)

regex for that I think should be: \d{1,3}

my cfinput has: validate="regular_expression" pattern="\d{1,3}"

but it doesn't seem to be working - I can enter 1000 and it submits ok.

It seems to be there in the source ok:

//form element quan_20 'REGULAR_EXPRESSION' validation checks
if (!_CF_checkregex(_CF_this['quan_20'].value, /\d{1,3}/, true))

This is CF7 - am I missing something?
552
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
LEGEND ,
May 16, 2008 May 16, 2008
SteveLogan1029 wrote:
> I need to match any number up to a 3 digits (e.g., 0 -> 999)
>
> regex for that I think should be: \d{1,3}
> ...
> This is CF7 - am I missing something?

Not quite. your regex will match any string that has one to three
digits in a row. It does not say anything about it the string contains
anything else as well. I.E. '123', '1234' and 'a string with 69 a
number in it' will all return true. Since they all have one to three
digits somewhere in them.

To do what you want you need to anchor the regex so that it does not
allow anything else to exist.

Regex: ^\d{1,3}&

The '^' specifies that this must be at the beginning of the string.

The '&' specifies that this must be at the end of the string.

In other words a string with one to three digits and nothing else.
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
Advocate ,
May 16, 2008 May 16, 2008
I haven't used regular expressions in the validate attribute, but its possible that CF might not support "\d"? Have you tried:

[0-9]{1,3}

to see if that works?
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
LEGEND ,
May 16, 2008 May 16, 2008
> The '&' specifies that this must be at the end of the string.

"$" - not "&" - I reckon.

--
Adam
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
LEGEND ,
May 20, 2008 May 20, 2008
LATEST
Adam Cameron wrote:
>> The '&' specifies that this must be at the end of the string.
>
> "$" - not "&" - I reckon.
>

Yeah what Adam says. I was a zombie last Friday. My fingers where
pretty much on their own and typed what they wanted.
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