title: Checking for several possible values in the 'name' field in an azure policy
body: <p>I have an azure policy for that enforces a naming convention for app services of 'kind' api. I got it mostly working. The policy should allow for the creation of app services that follow this format (??-<em>-api-dev, ??-</em>-api-stage, ??-*-api-prod). Everything was working until I put in the last bit to check for the -environment part. Policy is now allowing resource creation no matter what is put in the name field.</p>
  <p>Below is the json of my definition:</p>
  <pre><code>{
    &quot;mode&quot;: &quot;All&quot;,
    &quot;policyRule&quot;: {
      &quot;if&quot;: {
        &quot;allOf&quot;: [
          {
            &quot;field&quot;: &quot;type&quot;,
            &quot;match&quot;: &quot;Microsoft.Web/sites&quot;
          },
          {
            &quot;field&quot;: &quot;kind&quot;,
            &quot;match&quot;: &quot;api&quot;
          },
          {
            &quot;not&quot;: {
              &quot;anyOf&quot;: [
                {
                  &quot;value&quot;: &quot;[if(greaterOrEquals(length(split(field('name'), '-')), 4), split(field('name'), '-')[0], 'length of name incorrect')]&quot;,
                  &quot;match&quot;: &quot;??&quot;
                },
                {
                  &quot;value&quot;: &quot;[if(greaterOrEquals(length(split(field('name'), '-')), 4), split(field('name'), '-')[1], 'length of name incorrect')]&quot;,
                  &quot;match&quot;: &quot;*&quot;
                },
                {
                  &quot;value&quot;: &quot;[if(greaterOrEquals(length(split(field('name'), '-')), 4), split(field('name'), '-')[2], 'length of name incorrect')]&quot;,
                  &quot;equals&quot;: &quot;api&quot;
                },
                {
                  &quot;value&quot;: &quot;[if(greaterOrEquals(length(split(field('name'), '-')), 4), split(field('name'), '-')[3], 'length of name incorrect')]&quot;,
                  &quot;notIn&quot;: &quot;[parameters('validEnvironments')]&quot;
                }
              ]
            }
          }
        ]
      },
      &quot;then&quot;: {
        &quot;effect&quot;: &quot;deny&quot;
      }
    },
    &quot;parameters&quot;: {
      &quot;validEnvironments&quot;: {
        &quot;type&quot;: &quot;Array&quot;,
        &quot;metadata&quot;: {
          &quot;displayName&quot;: &quot;Allowed Environments&quot;,
          &quot;description&quot;: &quot;The list of environments that can be specified during resource deployment.&quot;
        },
        &quot;allowedValues&quot;: [
          &quot;dev&quot;,
          &quot;stage&quot;,
          &quot;prod&quot;
        ],
        &quot;defaultValue&quot;: [
          &quot;dev&quot;,
          &quot;stage&quot;,
          &quot;prod&quot;
        ]
      }
    }
  }
  </code></pre>