Message Profanity Filter

You can validate messages by using below function
Add this function in the authentication script

validateMessage: function(message) {
  //Add your code to filter messages. Below is the example of filtering phone number
        var phoneRe = /^[(]{0,1}[0-9]{3}[)]{0,1}[-\s\.]{0,1}[0-9]{3}[-\s\.]{0,1}[0-9]{4}$/;
      var digits = message.replace(/\D/g, "");
      return !phoneRe.test(digits);
   }

Example

<script>
window.applozic.init({
   appId: '<APP_ID>',      //Get your App ID from https://console.applozic.com/settings/install
   userId: 'jsfiddle',                     //Logged in user's id, a unique identifier for user
   userName: 'JSFiddler',                 //User's display name
   imageLink : '',                     //User's profile picture url
   email : '',
   contactNumber: '',
   desktopNotification: true,
   notificationIconLink: 'https://www.applozic.com/favicon.ico',    //Icon to show in desktop notification
   validateMessage: function(message) {
     // Profanity filter function
        var phoneRe = /^[(]{0,1}[0-9]{3}[)]{0,1}[-\s\.]{0,1}[0-9]{3}[-\s\.]{0,1}[0-9]{4}$/;
      var digits = message.replace(/\D/g, "");
      return !phoneRe.test(digits);
   },
   onInit : function(response) {
      if (response === "success") {
         // login successful, perform your actions if any, for example: load contacts, getting unread message count, etc
      } else {
         // error in user login/register (you can hide chat button or refresh page)
      }
  },
  contactDisplayName: function(otherUserId) {
        //return the display name of the user from your application code based on userId.
        return "";
  },
  contactDisplayImage: function(otherUserId) {
        //return the display image url of the user from your application code based on userId.
        return "";
  }
 });
<script>

What’s Next
Did this page help you?