1
votes

I have created a VSTS task with certain inputs. One of which is supposed to accept only comma separated email address. If it is was a simple email field I could validate like below:

{
  "name": "urlField",
  "type": "string",
  "label": "URL",
  "defaultValue": "",
  "required": true,
  "helpMarkDown": "Specify URL.",
  "validation": { 
        "expression": "isUrl(value)",
        "message": "InvalidURL"
    }     
},

I refered https://github.com/Microsoft/vsts-tasks/blob/master/docs/taskinputvalidation.md and https://www.npmjs.com/package/json-input-validator. But for my requirement I'd need to specify custom validator method like 'isUrl()'. I want to know where that can be done and how that can be associated to the task or if there is any way to provide regex or split the value here and run method on each section. Any idea is appreciated.

1
The documentation you referred has a "isMatch" method. Does it not meet your requiement? - Eddie Chen - MSFT
Yes that worked. - Rewati
Glad to hear that. :) - Eddie Chen - MSFT

1 Answers

0
votes

I used a regular expression to achieve this. There is method available for validation which does the regex matching:

isMatch(value: string, regEx: string, regExOptions: string)

I used below for semi colon separated URLs

  "validation": { 
          "expression": "isMatch(value,'^(((http|https){1}:\\/\\/([a-z0-9A-Z])+(([\\-\\.]{1}[a-z0-9A-Z]+)*)+(\\/[a-z0-9A-Z]+([\\-\\.]{1}[a-z0-9A-Z]+)*)*)(:[0-9]+){0,1})+(;(((http|https){1}:\\/\\/([a-z0-9A-Z])+(([\\-\\.]{1}[a-z0-9A-Z]+)*)+(\\/[a-z0-9A-Z]+([\\-\\.]{1}[a-z0-9A-Z]+)*)*)(:[0-9]+){0,1}))*$','IgnoreCase')",
          "message": "Each semicolon separated value must be a valid URL."
      }

and below for semi colon separated Emails addresses:

  "validation": { 
          "expression": "isMatch(value,'^([\\w+-.%]+@[\\w-.]+\\.[A-Za-z]{2,4})+(;[\\w+-.%]+@[\\w-.]+\\.[A-Za-z]{2,4})*$','IgnoreCase')",
          "message": "Each semicolon separated value must be a valid UPN."
      }