#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: |
Description
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 http://www.regular-expressions.info/javascriptexample.html :
$((\d+\.\d{1,2})|(\d+))
This does what I want it to do, but when I feed this into a validation textbox using:
regExp="[(\d+\.\d{1,2})|(\d+)]"
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:
((?:(?:((?:(?:(?:(?:0|[1-9]\d{0,2}(?:[,]\d{3})*)|(?:0|[1-9]\d*))(?:\.\d{0,3}|))|(?:(?:\.\d{0,3}|)))))|(?:-((?:(?:(?:(?:0|[1-9]\d{0,2}(?:[,]\d{3})*)|(?:0|[1-9]\d*))(?:\.\d{0,3}|))|(?:(?:\.\d{0,3}|)))))))?$
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.
Thanks,
Josh
Change History (7)
comment:1 Changed 14 years ago by
comment:2 Changed 14 years ago by
Owner: | set to Douglas Hays |
---|---|
Summary: | bug in regExp parsing of ValidationTextBox → ValidationTextBox : 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
Resolution: | → invalid |
---|---|
Status: | new → closed |
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
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 follow-up: 6 Changed 14 years ago by
RangeBoundTextBox? with your regExp attribute should do it
comment:6 Changed 14 years ago by
Replying to doughays:
RangeBoundTextBox? with your regExp attribute should do it
Thank you - works great!
comment:7 Changed 11 years ago by
Component: | Dijit → Dijit - Form |
---|
I meant to say "validator" method above.
Also - I tried adding in the anchors using:
regExp="$((\d+\.\d{1,2})|(\d+))"
No change as these appear to be stripped and hard coded into the validator method.