Opened 14 years ago

Closed 14 years ago

Last modified 11 years ago

#7378 closed defect (invalid)

ValidationTextBox : bug in regExp parsing

Reported by: Josh Trutwin Owned by: Douglas Hays
Priority: high Milestone: tbd
Component: Dijit - Form Version: 1.1.1
Keywords: regExp validation parse Cc: [email protected]
Blocked By: Blocking:


I wanted to create a reg exp that validated a number had up to at most 2 decimal places, or none. (e.g. 50, 50.1, 50.98 but not 50.982)

I tested the following regular expression here :


This does what I want it to do, but when I feed this into a validation textbox using:


It doesn't work as expected, also tried replacing square brackets with parans, no change. Digging into this, it seems that the regular expression test that is being run is on the following regexp in the ValidationTextBox? validate() routine:


I don't pretend to understand what this is doing, but it doesn't work. It'll accept a number with 3 decimals but not 4. Why did my regexp get turned into this beast?

I'm not sure if it matters but I also have a constraint of min:0 on the textbox.



Change History (7)

comment:1 Changed 14 years ago by Josh Trutwin

I meant to say "validator" method above.

Also - I tried adding in the anchors using:


No change as these appear to be stripped and hard coded into the validator method.

comment:2 Changed 14 years ago by bill

Owner: set to Douglas Hays
Summary: bug in regExp parsing of ValidationTextBoxValidationTextBox : bug in regExp parsing

Doug, sounds like the partial matching stuff?

Josh - btw you can adjust trac settings to automatically email you w/out putting your name in the CC field.

comment:3 Changed 14 years ago by Douglas Hays

Resolution: invalid
Status: newclosed

The partial match output you listed indicates that the widget type must not have been dijit.form.ValidationTextBox?, but a subclass like NumberTextBox? which has a hardcoded regExp. Also, the regExp attribute should have been specified as "(\d+\.\d{1,2})|(\d+)". I changed the regExp in the q22 example in dijit/form/test_validate.html and it worked perfectly.

comment:4 Changed 14 years ago by Josh Trutwin

You are right - it was a NumberTextBox?, my bad, should've included that minute detail. :P

There is still problem though - if I change this to a ValidationTextBox?, I lose the ability to set a min constraint.

Is there a regExp I can pass to ValidationTextBox? that says the results must be numeric, with at most 2 decimal places and also greater than or less than some max/min?

comment:5 Changed 14 years ago by Douglas Hays

RangeBoundTextBox? with your regExp attribute should do it

comment:6 in reply to:  5 Changed 14 years ago by Josh Trutwin

Replying to doughays:

RangeBoundTextBox? with your regExp attribute should do it

Thank you - works great!

comment:7 Changed 11 years ago by bill

Component: DijitDijit - Form
Note: See TracTickets for help on using tickets.