EN VI

how do I filter individual characters with regex?

2024-03-16 00:30:10
how do I filter individual characters with regex

I need a regex that allows me to use all characters except |. I need this for a text input in a flutter app. Here I want to make sure that this character is not present in the text. The widget in which I use this looks like this.

                     TextField(
                        inputFormatters: [
                          FilteringTextInputFormatter.allow(
                             RegExp(>>regex here<<)),
                        ],
                        maxLength: 20,
                        controller: titleEditingController,
                        decoration: const InputDecoration(
                          hintText: 'Title',
                          label: Text("Title"),
                        ),
                      ),

Solution:

Use the deny method, and the following Regex - [|].

FilteringTextInputFormatter.deny(RegExp(r'[|]'))
Answer

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login