Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pattern with regex not working as expected #667

Open
AnyaHunt opened this issue May 14, 2019 · 1 comment
Open

Pattern with regex not working as expected #667

AnyaHunt opened this issue May 14, 2019 · 1 comment

Comments

@AnyaHunt
Copy link

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.

@ellenhutchings
Copy link

I think for javascript you may be missing the leading and ending forward slashes
/^[^\/\\\^\$\.\|\?\*\+\(\)\"\']+$/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants