Flutter: Input Validation with RegExp

Andrea Bizzotto
Code With Andrea
Published in
2 min readOct 12, 2018

Today I’m launching a new video about Input Validation and RegExp.

As part of this, I’ll give you an overview of regular expressions (regex) and how they works by using a live web regex validator.

Then we will see how to implement a Regex validator in Dart and integrate it with Flutter’s TextField widget, so that we can validate user input.

I will use a demo app to illustrate two sample use cases:

  • Make a payment (numeric validator with 2 decimal digits, 4 non-decimal digits)
  • Forgot password (email input validation)

Highlights

  • What is Regex and how to use it.
  • Implementing a Regex validator in Dart.
  • How to configure TextField to validate text input and provide hints for the user.
  • Email and number input validation via Regex.
  • Putting it together: building a configurable input validation page.

Relevant classes: RegExp, TextField, TextInputFormatter, InputDecoration, FocusNode​.

Full source code is available here:

My previous articles about BottomAppBar navigation with FAB:

Happy coding!

UPDATE: My Flutter & Firebase Udemy course is now available for Early Access. Use this link to enroll (discount code included):

For more articles and video tutorials, check out Code With Andrea.

I’m @biz84 on Twitter. You can also see my GitHub page. Did you like this article? Then smash that clap 👏 button! It makes me feel awesome so I can write more about Flutter. 😎

--

--