Microsoft.Common.TextBox UI 元素Microsoft.Common.TextBox UI element

一个可用来编辑无格式文本的控件。A control that can be used to edit unformatted text.

UI 示例UI sample



    "name": "nameInstance",
    "type": "Microsoft.Common.TextBox",
    "label": "Name",
    "defaultValue": "contoso123",
    "toolTip": "Use only allowed characters",
    "placeholder": "",
    "constraints": {
        "required": true,
        "validations": [
                "regex": "^[a-z0-9A-Z]{1,30}$",
                "message": "Only alphanumeric characters are allowed, and the value must be 1-30 characters long."
                "isValid": "[startsWith(steps('resourceConfig').nameInstance, 'contoso')]",
                "message": "Must start with 'contoso'."
    "visible": true

示例输出Sample output



  • 如果 constraints.required 设置为 true,则文本框必须包含值才能成功通过验证 。If constraints.required is set to true, then the text box must have a value to validate successfully. 默认值是 false秒。The default value is false.
  • validations 属性是一个数组,可在其中添加条件,用于检查文本框中提供的值。The validations property is an array where you add conditions for checking the value provided in the text box.
  • regex 属性是一个 JavaScript 正则表达式模式。The regex property 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.
  • isValid 属性包含计算结果为 true 或 false 的表达式。The isValid property contains an expression that evaluates to true or false. 在表达式中,定义确定文本框是否有效的条件。Within the expression, you define the condition that determines whether the text box is valid.
  • message 属性是当文本框的值未通过验证时会显示的一个字符串。The message property is a string to display when the text box's value fails validation.
  • required 设置为 false 时可以为 regex 指定值。It's possible to specify a value for regex when required is set to false. 在这种情况下,文本框并非必须具有值才能成功通过验证。In this scenario, a value isn't required for the text box to validate successfully. 如果指定了一个值,则它必须与正则表达式模式匹配。If one is specified, it must match the regular expression pattern.
  • placeholder 属性是帮助文本,当用户开始编辑后会消失。The placeholder property is help text that disappears when the user begins editing. 如果同时定义了 placeholderdefaultValue,会优先显示 defaultValueIf the placeholder and defaultValue are both defined, the defaultValue takes precedence and is shown.


以下实例结合使用 Microsoft.Solutions.ArmApiControl 控件和文本框来检查资源名称的可用性。The following example uses a text box with the Microsoft.Solutions.ArmApiControl control to check the availability of a resource name.

"basics": [
        "name": "nameApi",
        "type": "Microsoft.Solutions.ArmApiControl",
        "request": {
            "method": "POST",
            "path": "[concat(subscription().id, '/providers/Microsoft.Storage/checkNameAvailability?api-version=2019-06-01')]",
            "body": "[parse(concat('{\"name\": \"', basics('txtStorageName'), '\", \"type\": \"Microsoft.Storage/storageAccounts\"}'))]"
        "name": "txtStorageName",
        "type": "Microsoft.Common.TextBox",
        "label": "Storage account name",
        "constraints": {
            "validations": [
                    "isValid": "[not(equals(basics('nameApi').nameAvailable, false))]",
                    "message": "[concat('Name unavailable: ', basics('txtStorageName'))]"

后续步骤Next steps