Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restrict all kinds of emojis in Text Field in flutter

I am looking for a way using which there should be no emoji character allowed in the textfield

or else a way to find out if there is a emoji present in a string or not [regex]

any one way of it could workout.

I have gone through all the related questions and their solutions but they don't cover the entire use cases.

like image 724
Vicky Salunkhe Avatar asked Oct 21 '25 11:10

Vicky Salunkhe


1 Answers

Eventually I Found the solution to the query so posting the answer here.

For the first part Restrict Emoji's in textfield

add below code inside your textfield widget.

inputFormatters: [
   BlacklistingTextInputFormatter(
     RegExp('(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])')
],

this will prevent all kinds of emoji's from the textfield.

2nd part

if there is a emoji present in a string or not [regex]

below mentioned code will detect if any emoji is present in the string or not

if(string.contains(RegExp(r'(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])'))){
   // your code here
}
like image 158
Vicky Salunkhe Avatar answered Oct 24 '25 01:10

Vicky Salunkhe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!