Skip to content

Latest commit

 

History

History
26 lines (21 loc) · 960 Bytes

template-validation.md

File metadata and controls

26 lines (21 loc) · 960 Bytes

Template Data Validation

Support template data validation by adding required fields (minimal dataset) and regular expression validation. A non-required field can still be validated by a regular expression, if a value has been provided.

  1. Add an optional property to the data object: required (boolean)
  2. Add an optional property to the data object: regexp (string pattern)
{ "collection" :
  {
    "version" : "1.0",
    "href" : "http://example.org/users",

    "template" : {
      "data" : [
        {"name" : "username", "value" : "", "prompt" : "Login Name", "regexp" : "^[a-zA-Z0-9]*$", "required" : "true"},
        {"name" : "email", "value" : "", "prompt" : "Email", "regexp" : "^[\w\d.@]*$", "required" : "true"},
        {"name" : "gender", "value" : "", "prompt" : "Gender", "regexp" : "^(m|f)$"}
      ]
    }
  }
}

References

  1. https://groups.google.com/forum/#!topic/collectionjson/RPQcM_WX7Y0