DS Specifications
Domain SpecificationsListsVocabularies
main
main
  • DS Specifications Overview
  • Domain Specifications
    • DS-V7
      • DS-V7 - Changelog
      • DS-V7 - Developer Notes
      • DS-V7 - Grammar
        • Domain Specification
          • @Context
          • Domain Specification Node
          • Property Node
          • Class Node
          • DataType Node
          • Enumeration Node
        • Verification Report
          • Verification Report Node
          • Error Entry Node
          • Error List for the domain-specific verification
        • DS-Path
      • DS-V7 - Examples
    • DS-V6
    • DS-V5
      • DS-V5 - Grammar
        • VerificationReport
          • Error List for the basic verification
          • Verification of schema.org annotations
          • Error List for the Meta verification of DS (unfinished)
          • Error List for the DS-based verification
        • Grammar and semantics of Domain Specifications
          • Enumeration Node
          • Property Node
          • Domain Specification Node
          • Class Node
          • Terms used in Domain Specifications
          • @Context
          • DataType Node
      • DS-V5 - Examples
    • DS-V4
    • DS-V3
      • DS-V3 - Examples
      • DS-V3 - Grammar
        • VerificationReport
          • Error List for the basic verification
          • Verification of schema.org annotations
          • Error List for the DS-based verification
          • Error List for the Meta verification of DS
        • Grammar and semantics of Domain Specifications
          • SDO Enumeration
          • SDO Property
          • Domain Specification
          • SDO Class
          • SDO Datatype
          • @Context
    • DS-V2
      • DS-V2 - Grammar
        • Grammar and semantics of Domain Specifications
          • Grammar Documentation for node type "RestrictedEnumeration"
          • Grammar Documentation for node type "CustomEnumerationValue"
          • Grammar Documentation for node type "Enumeration"
          • Grammar Documentation for node type "Property"
          • Grammar Documentation for node type "RestrictedProperty"
          • Grammar Documentation for node type "DomainSpecification"
          • Grammar Documentation for node type "RestrictedClass"
          • Grammar Documentation for node type "EnumerationValue"
          • Grammar Documentation for node type "Class"
          • Grammar Documentation for node type "DataType"
        • Numeric Pattern
        • Grammar Documentation for node type "VerificationReport"
          • Grammar Documentation for node type "Error"
          • Error codes for Verification Reports
        • Rules Grammar
          • Grammar Documentation for node type "ComplexRule"
          • Grammar Documentation for node type "DateRule"
          • Grammar Documentation for node type "TextRule"
          • Grammar Documentation for node type "TimeRule"
          • Grammar Documentation for node type "NumberRule"
          • Grammar Documentation for node type "BooleanRule"
          • Grammar Documentation for node type "DateTimeRule"
      • DS-V2 - Examples
    • DS-V1
      • DS-V1 - Examples
      • DS-V1 - Grammar
  • SDO-Verification
  • Lists
    • List-V1
  • Vocabularies
  • DS-Vocabulary
    • Input
      • Vocabulary for Domain Specifications
      • DS-Vocabulary
    • DS-Vocab-V1
Powered by GitBook
On this page
  • hasLength
  • equals
  • startsWith
  • endsWith
  • contains
  • isInSet
  • matchesPattern
  • hasFormat
  1. Domain Specifications
  2. DS-V2
  3. DS-V2 - Grammar
  4. Rules Grammar

Grammar Documentation for node type "TextRule"

PreviousGrammar Documentation for node type "DateRule"NextGrammar Documentation for node type "TimeRule"

Last updated 4 years ago

TextRules are rules that apply on values which have the data type "Text" or "URL" from Schema.org.

The specific rule type is given by the value in the "$rule" property. The properties which rules can have are explained in the Meta_Rules.md document. Note that the "subject" property can be omitted, if the "$path" object has an empty JSON Pointer as value (see Meta_Rules.md for details).

However, the data type for the "parameter" depends on the "$rule" value (e.g. arguments for the rule function), and is explained in the following.

hasLength

The "hasLength" rule compares the length of a given Text (the validated subject) with a given numeric pattern. The constraint is fulfilled if the length of the string matches the numeric pattern.

{
  "$type": "TextRule",
  "$rule": "hasLength",
  "subject": {
      "$path": "/name"
   },
  "parameter": "(>4 & <20)"
}

The parameter is a numeric pattern that serves as the second argument for the rule function. The constraint is fulfilled if the length of the string matches the numeric pattern.

equals

{
  "$type": "TextRule",
  "$rule": "equals",
  "parameter": "Austria"
}

The parameter is a string which serves as the second argument for the rule function. The given Text (the validated subject) must be the same as the given parameter. The comparison is case sensitive!

startsWith

{
  "$type": "TextRule",
  "$rule": "startsWith",
  "parameter": "+43"
}

The parameter is a string that serves as the second argument for the rule function. The given Text (the validated subject) must have the given parameter as substring at the start. The comparison is case sensitive!

endsWith

{
  "$type": "TextRule",
  "$rule": "endsWith",
  "parameter": "hausen"
}

The parameter is a string that serves as the second argument for the rule function. The given Text (the validated subject) must have the given parameter as substring at the end. The comparison is case sensitive!

contains

{
  "$type": "TextRule",
  "$rule": "contains",
  "parameter": "0664"
}

The parameter is a string which serves as the second argument for the rule function. The given Text (the validated subject) must have the given parameter as substring at any position. The comparison is case sensitive!

isInSet

The "isInSet" rule checks if a given Text (the validated subject) is in the given set of allowed values.

{
  "$type": "TextRule",
  "$rule": "isInSet",
  "parameter": [
    "Austria",
    "Germany",
    "Switzerland"
  ]
}

The parameter is an array that contains strings, which are valid instances for the given Text (the validated subject).

matchesPattern

{
  "$type": "TextRule",
  "$rule": "matchesPattern",
  "parameter": "^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$",
  "description": "email address using pattern according to RFC 5322"
}

The parameter is a regex that serves as the second argument for the rule function. The given Text (the validated subject) must match the regex in order to be valid.

hasFormat

{
  "$type": "TextRule",
  "$rule": "hasFormat",
  "parameter": "email",
  "description": "email address validation with built in format according to RFC 5322"
}

The parameter is a string that serves as the second argument for the rule function. The passed "format" must be one of the pre-defined formats of the DS vocabulary.

Pre-defined Formats for the Domain Specification context SHOULD be based on properties and intangibles of Schema.org which expect a special string as value. (todo: investigate which formats are interesting)

The "equals" rule checks if a given Text (the validated subject) matches a given string. Based on

The "startsWith" rule checks if a given Text (the validated subject) starts with a given string. Based on

The "endsWith" rule checks if a given Text (the validated subject) ends with a given string. Based on

The "contains" rule checks if a given Text (the validated subject) includes a given string at any position. Based on

The "matchesPattern" rule checks if a given Text (the validated subject) matches a given regular expression. Based on

The Regex pattern is expected to work with a javascript engine Note that the regex must be escaped so that it can be included as JSON value. The regex shall be unescaped before it can be passed to the regex validation function.

The "hasFormat" rule checks if a given Text (the validated subject) matches a given pre-defined format. Like the pattern constraint of JSON Schema, the pre-defined formats are based on specifications provided by official authorities (see ) OR formats specified by Schema.org

email for

telephone number for

https://www.ecma-international.org/ecma-262/6.0/#sec-abstract-equality-comparison
https://www.ecma-international.org/ecma-262/6.0/#sec-string.prototype.startswith
https://www.ecma-international.org/ecma-262/6.0/#sec-string.prototype.endswith
https://www.ecma-international.org/ecma-262/6.0/#sec-string.prototype.includes
https://www.ecma-international.org/ecma-262/6.0/#sec-string.prototype.match
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
https://json-schema.org/understanding-json-schema/reference/string.html
https://schema.org/URL
https://schema.org/email
https://schema.org/Duration
https://schema.org/Distance
https://schema.org/Mass
https://schema.org/Energy
https://schema.org/telephone
Syntax diagram