Restrict all kinds of emojis in Text Field in flutter
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
}
Vicky Salunkhe
Full Stack Developer Interested in solving complex problems and building real-world solutions. 👨🏻💻🏆🙌🏻 Visit vickysalunkhe.in to know more about me. 👨🏻💻 My LinkedIN Profile 👉🏻 Linked In
Updated on December 19, 2022Comments
-
Vicky Salunkhe over 1 year
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.