Microsoft.Compute.UserNameTextBox UI 元素Microsoft.Compute.UserNameTextBox UI element

一个具有针对 Windows 和 Linux 用户名的内置验证的文本框控件。A text box control with built-in validation for Windows and Linux user names.

UI 示例UI sample

Microsoft.Compute.UserNameTextBox

架构Schema

{
  "name": "element1",
  "type": "Microsoft.Compute.UserNameTextBox",
  "label": "User name",
  "defaultValue": "",
  "toolTip": "",
  "constraints": {
    "required": true,
    "regex": "^[a-z0-9A-Z]{1,30}$",
    "validationMessage": "Only alphanumeric characters are allowed, and the value must be 1-30 characters long."
  },
  "osPlatform": "Windows",
  "visible": true
}

示例输出Sample output

"Example name"

备注Remarks

  • 如果 constraints.required 设置为 true,则文本框必须包含值才能成功通过验证 。If constraints.required is set to true, then the text box must have a value to validate successfully. 默认值为 trueThe default value is true.
  • 必须指定 osPlatform,它可以是 WindowsLinuxosPlatform must be specified, and can be either Windows or Linux.
  • constraints.regex 是一个 JavaScript 正则表达式模式。constraints.regex is a JavaScript regular expression pattern. 如果指定,则文本框的值必须与模式完全匹配才能成功通过验证。If specified, then the text box's value must match the pattern to validate successfully. 默认值为 nullThe default value is null.
  • constraints.validationMessage 是当文本框的值未通过 constraints.regex 指定的验证时会显示的一个字符串。constraints.validationMessage is a string to display when the text box's value fails the validation specified by constraints.regex. 如果未指定,则会使用文本框的内置验证消息。If not specified, then the text box's built-in validation messages are used. 默认值为 nullThe default value is null.
  • 此元素具有基于为 osPlatform 指定的值的内置验证。This element has built-in validation that is based on the value specified for osPlatform. 内置验证可以与自定义正则表达式一起使用。The built-in validation can be used along with a custom regular expression. 如果指定了 constraints.regex 的值,则会同时触发内置验证和自定义验证。If a value for constraints.regex is specified, then both the built-in and custom validations are triggered.

后续步骤Next steps