How to restrict emoji's in appcelerator when user entered in a textArea?

274 views Asked by At

I am developing an iOS app.In i have a textfield where user can give a comment.he can able to give emojis also .when he click on send button i need to check whether he entered emoji's or not.Can any help me how to check whether user entered emoji's or not.

Thanks in advance..

1

There are 1 answers

2
Andrés Andrade On

You can use a regular expression to search emojis in your text:

/\ud83d[\ude00-\ude4f]/g.test('')

To replace characters with the corresponding unicode escape sequence you can use:

function toUnicodeSequence(str) {
  return str.replace(/[\s\S]/g, function(c) {
    return '\\u' + ('000' + c.charCodeAt(0).toString(16)).slice(-4);
  });
}