Knockout-Contrib / Knockout-Contrib/Knockout-Validation

Pattern with regex not working as expected

Open
#667 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1k
Forks
366
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

Research direction

Start with the pattern validator used by the knockout observable's extend definition and reproduce the supplied regular expression, focusing on why it does not detect a backslash while detecting the other escaped characters. Confirm the expected behavior against the complete required, maxLength, and pattern definition; done means backslashes are detected without regressing the other listed characters.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.