I have the following PowerShell function, where I'm validating that the parameter is a number, or a set of numbers separated by commas, or a range of numbers.
function CheckUpkeep() {
Param(
[ValidatePattern("\d+(,|-\d+)*")]
[Parameter(Mandatory = $true, Position=0)]
$ID
)
Write-Output "ID: $ID"
}
Example of valid ways to call this are:
CheckUpkeep 1
CheckUpkeep 1-10
CheckUpKeep 1-3,5-10
Output for 1-10 case:
ID: 1-10
Output for 1-3,5-10 case:
ID: 1-3 5-10
How do I update the regex so that the comma is captured as well, without having to use a string quote (whether single or double) when calling the function (CheckUpkeep "1-3,5-10") , such that for the 1-3,5-10 case when I call:
CheckUpkeep 1-3,5-10
the output is:
ID: 1-3,5-10
Thanks!