Skip to content

Pattern with regex not working as expected #667

Description

@AnyaHunt

I have really liked using knockout-validation. I think it works well. I've just come across one small thing (that has been verified by someone else). I have a knockout observable (string) with the following validation extend definition

pattern: {
     message: this.gui.validationCannotInclude,
     params: '^[^\/\\\^\$\.\|\?\*\+\(\)\"\']+$'
}

It works fine detecting all of the escaped characters, except \ - it even catches /. I've checked the regex in https://www.regextester.com/ and it seems correct. Attempted rewriting the regex to put the backslash elsewhere in the definition, but it doesn't help.

The complete definition on this observable is:

ko.observable(this.Name).extend({
required: {
    message: this.gui.validationRequired
},
maxLength: {
    params: 50,
    message: this.gui.validationLongerThan50
},
pattern: {
   message: this.gui.validationCannotInclude,
   params: '^[^\/\\\^\$\.\|\?\*\+\(\)\"\']+$'
}

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions