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.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With