mirror of
https://github.com/divkit/divkit.git
synced 2026-06-06 20:07:59 +00:00
Fix regex input validator
This commit is contained in:
@@ -91,7 +91,7 @@ extension DivInput {
|
||||
return TextInputValidator(
|
||||
isValid: context.makeBinding(variableName: regexValidator.variable, defaultValue: false),
|
||||
allowEmpty: regexValidator.resolveAllowEmpty(expressionResolver),
|
||||
validator: { $0.matchesRegex(regex) },
|
||||
validator: { $0.fullMatchesRegex(regex) },
|
||||
message: makeMessage(
|
||||
from: regexValidator.resolveLabelId(expressionResolver),
|
||||
storage: context.blockStateStorage,
|
||||
@@ -231,3 +231,11 @@ extension DivFixedLengthInputMask.PatternElement {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
extension String {
|
||||
fileprivate func fullMatchesRegex(_ regex: NSRegularExpression) -> Bool {
|
||||
let range = stringRangeAsNSRange(wholeStringRange, inString: self)
|
||||
return regex.matches(in: self, options: [], range: range)
|
||||
.contains { $0.range == range }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user