std::string WRegExpValidator::javaScriptValidate() const { loadJavaScript(WApplication::instance()); WStringStream js; js << "new " WT_CLASS ".WRegExpValidator(" << isMandatory() << ','; if (regexp_) { js << WWebWidget::jsStringLiteral(regexp_->pattern()) << ",'"; #ifndef WT_TARGET_JAVA WFlags<RegExpFlag> flags = regexp_->flags(); #else int flags = regexp_->flags(); #endif if (flags & MatchCaseInsensitive) js << 'i'; js << '\''; } else js << "null, null"; js << ',' << WWebWidget::jsStringLiteral(invalidBlankText()) << ',' << WWebWidget::jsStringLiteral(invalidNoMatchText()) << ");"; return js.str(); }
WValidator::Result WRegExpValidator::validate(const WT_USTRING& input) const { if (input.empty()) return WValidator::validate(input); if (std::regex_match(input.toUTF8(), regex_)) return Result(ValidationState::Valid); else return Result(ValidationState::Invalid, invalidNoMatchText()); }
WValidator::Result WRegExpValidator::validate(const WT_USTRING& input) const { if (input.empty()) return WValidator::validate(input); if (!regexp_ || regexp_->exactMatch(input)) return Result(Valid); else return Result(Invalid, invalidNoMatchText()); }
std::string WRegExpValidator::javaScriptValidate() const { loadJavaScript(WApplication::instance()); WStringStream js; js << "new " WT_CLASS ".WRegExpValidator(" << isMandatory() << ','; js << WWebWidget::jsStringLiteral(pattern_) << ",'"; if (regex_.flags() & std::regex::icase) js << 'i'; js << '\''; js << ',' << WWebWidget::jsStringLiteral(invalidBlankText()) << ',' << WWebWidget::jsStringLiteral(invalidNoMatchText()) << ");"; return js.str(); }