Opened 10 years ago

Closed 9 years ago

#16510 closed defect (worksforme)

unable to escape single quote in ValidationTextBox pattern

Reported by: [email protected] Owned by: Douglas Hays
Priority: undecided Milestone: tbd
Component: Dijit - Form Version: 1.8.1
Keywords: Cc:
Blocked By: Blocking:


Problem: In ValidationTextBox?, you cannot escape a single quote into the regExp pattern.

Background: This defect seems to have happened with the introduction of the AMD format. In 1.7.0, under the non-AMD format, you would specify the regExp as:

regExp="^[A-Za-z '\-\.]{1,50}$"

and this worked fine, allowing names such as O'Donnell.

However, in the AMD format (tested against 1.8.1), you must specify the regExp pattern within data-dojo-props="". Within that, the regExp pattern must be wrapped in single quotes, such as:

pattern:'^[A-Za-z \\'\\-\\.]{1,50}$'

Escapes in the AMD format must be entered as double backslashes (as opposed to the single backslashes in the non-AMD), but even double backslashes do not properly escape the single quote.

I have tried the following combinations, but to no avail:

" (worked, but allowed a double quote)

I also tried:

  • removing the encapsulating single quotes from around the regExp pattern... no success
  • using other characters to encapsulate the regExp pattern... no success

Can you code the regExp pattern processing of ValidationTextBox? to properly allow for the escaping of a single quote character?

Change History (2)

comment:1 Changed 10 years ago by bill

data-dojo-props is unrelated to AMD. Also I don't see why there would be a problem escaping single quotes in data-dojo-props; and if there is, it probably isn't related to ValidationTextBox.

IIRC though the best way to specify the pattern nowadays would be:

data-dojo-props="pattern: /^[A-Za-z \\'\\-\\.]{1,50}$/"

I didn't try it, but if that works, then you don't need to worry about escaping at all.

Last edited 10 years ago by bill (previous) (diff)

comment:2 Changed 9 years ago by Douglas Hays

Resolution: worksforme
Status: newclosed

data-dojo-props='pattern:"\\x27[\\w]+\\x27"' works for me.

Note: See TracTickets for help on using tickets.