OneSpan Sign template - field validation
Thursday, April 13, 2023 at 11:18pmIs there a way to apply validation rules on field values during signing ceremony? We have bunch of phone number fields and email address fields. We want to make sure that signers enter these fields in a specific format.
Reply to: OneSpan Sign template - field validation
Friday, April 14, 2023 at 06:45amHi gberde,
Yes, you can add field validations and restrict field values during the signing ceremony. Note that you can't add Regular expressions via UI and consider you are using templates, try to update template fields with this API combination:
Step0: As a general backup method, you can make a copy of you template in this way: in your sender UI > "Templates" > "New Template" > for the "Use Template" option, choose the existing template from the dropdown list, give the newly created template a different name (template name is unique) then create
Step1:
GET /api/packages/{template_id}/documents/{document_id}/approvals/{approval_id}
This retrieves all the fields under an approval. From the response JSON, find your target fields by id/name and add a "validation" node to them. Below example gives you an idea of how to build the validation JSON:
{
"role": "client",
"fields": [
{
"validation": {
"required": true,
"errorMessage": "Please enter a valid phone number (XXX-XXX-XXXX)",
"pattern": "^[2-9]\\d{2}-\\d{3}-\\d{4}$"
},
"subtype": "TEXTFIELD",
"extract": true,
"type": "INPUT",
"name": "phone_number"
},
{
"validation": {
"required": true,
"errorMessage": "Please enter a valid email.",
"pattern": "^([a-z0-9_\\.-]+)@([\\da-z\\.-]+)\\.([a-z\\.]{2,6})$"
},
"subtype": "TEXTFIELD",
"extract": true,
"type": "INPUT",
"name": "email"
},
{
"subtype": "CAPTURE",
"extract": true,
"type": "SIGNATURE",
"name": "client_signature"
}
],
"name": ""
}
Step2:
With the updated payload by hand, you can update the fields under the signature by a PUT call:
PUT /api/packages/{template_id}/documents/{document_id}/approvals/{approval_id}
Duo