user2570135
user2570135

Reputation: 3009

How to prevent html tag in a flutter text widget

I have a Flutter text widget in my login screen that users enters their username in plain text. How can I prevent then from entering HTML characters in the field.

For example, they enter <p>myname</p>

Thanks

Upvotes: -1

Views: 172

Answers (1)

esentis
esentis

Reputation: 4696

You can try using RegEx for that like so

 String stripHtml(String s) {
    if (s.isEmpty) {
      return s;
    }
    var regex = RegExp(r'<[^>]*>');
    return s.replaceAll(regex, '');
  }

Upvotes: 1

Related Questions