@Ashar Siddiqui Welcome to Microsoft Q & A Community Forum. For your requirement , you can use below sample snippet to verify the prefix of the VM name and also vm name can be any number of characters.
{
"mode": "All",
"policyRule": {
"if": {
"allOf": [
{
"not": {
"value": "[substring(field('name'), 0, 3)]",
"equals": "swa"
}
},
{
"field": "type",
"equals": "Microsoft.Compute/virtualMachines"
}
]
},
"then": {
"effect": "deny"
}
},
"parameters": {}
}
Also, to check length of the VM name , you can use this value operator "[length(field('name'))]"
in your policy definition.