October 25, 2024
Chicago 12, Melborne City, USA
javascript

Validate Comma Separated String by JOI


I am implementing JOI validation and want to validate comma separated string by JOI. This string contain only particular text string like ‘admin’,’client’, ‘customer’, ‘user’. For example check below. I can validate this by JavaScript, but i want to validate by JOI

function checkString(perm)
{
    const a = ['admin','client', 'customer', 'user'];
     
    const check = perm.split(",");
     
    if(!check.every(val => a.includes(val)))
    {
            return false;
      }
     
      return true;
}
        
//alert(checkString('admin,client,customer'))            //true
//alert(checkString('customer'))                         //true
//alert(checkString('admin,client,buyer'))               //false
//alert(checkString('buyer'))                            //false
//alert(checkString('admin,client,customer,buyer'))      //false



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video