2

I am working on a chat application so the thing is one should not be able to send an empty message so for that I did following things

For empty spaces

 private boolean emptySpacecheck(String msg){

    return msg.matches(".*\\w.*");
}

For Special Characters

private boolean specCharcheck(String msg){

        return msg.matches("[$&+,:;=\\\\\\\\?@#|/'<>.^*()%!-]");

    }

Above code works fine if someone tries to send an empty message or message that contains only spaces it shows an error the problem it's showing error when trying to send only emoji as msg. How to check for emoji using regex?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Stackover67
  • 347
  • 2
  • 4
  • 18

1 Answers1

0

The solution below isn't the best solution but it works hope it helps and works in your situation.

There we go this fix should work it essentially goes in to the ascii value table checks if the characters are the everyday characters used if not it is either a weird character (not used everyday) or an emoji, hope this works.

  String userinp= userinput;
    for (int i=0;i<userinp.length()-1;i++){
    if (((int)userinp.charAt(i))>0&&((int)userinp.charAt(i))<127)
    System.out.println("not emoji");
    else
    System.out.println("emoji");
    }