验证器检查 HTML 格式中的输入字符串?

问题描述 投票:0回答:1

我需要在 flutter 应用程序中将 HTML 和 CSS 呈现为 Flutter 小部件。我从 API 得到了输入。我想先检查我得到的输入是否是 HTML 格式。

flutter dart validation
1个回答
0
投票

此功能检查您的输入是否为 HTML 格式。

        bool isHTML(String str) {
          final RegExp htmlRegExp =
              RegExp('<[^>]*>', multiLine: true, caseSensitive: false);
          return htmlRegExp.hasMatch(str);
        }

例子

            String input =
                "<p>Flutter is an open source framework by Google for building beautiful, natively compiled, multi-platform applications from a single codebase.</p>";
            
            bool isInHTMLFormat = Validator.isHTML(input); // output true

基于此,我们可以借助Flutter_html

显示 HTML 内容
© www.soinside.com 2019 - 2024. All rights reserved.