Here's an example of how you could set it up for a phone number:
a!localVariables(
local!phoneNumber,
/* Determines how many existing records */
/* have the same phone number */
local!phoneNumberMatching: if(
a!isNullOrEmpty(local!phoneNumber),
0,
/* Run a query with a filter by phone number. */
/* This could also use a!queryEntity() */
a!queryRecordType(
recordType: recordType!Employee
fields: {
recordType!Employee.fields.name,
recordType!Employee.fields.phoneNumber
},
pagingInfo: a!pagingInfo(
startIndex: 1,
batchSize: 1
),
filters: a!queryFilter(
field: recordType!Employee.fields.phoneNumber
operator: "=",
value: local!phoneNumber
)
).totalCount
),
/* Checks that the there are no matches */
local!phoneNumberIsValid: and(
a!isNotNullOrEmpty(local!phoneNumber),
local!phoneNumberMatching = 0
),
a!formLayout(
label: "Form",
contents: {
a!textField(
label: "Text",
labelPosition: "ABOVE",
saveInto: local!phoneNumber,
value: local!phoneNumber,
refreshAfter: "UNFOCUS",
validations: {
if(
local!phoneNumberIsValid,
null,
"This phone number has already been taken, please enter a different phone number"
),
}
)
},
buttons: a!buttonLayout(
primaryButtons: {
a!buttonWidget(
label: "Submit",
submit: true,
style: "PRIMARY",
loadingIndicator: true,
)
},
)
)
)
Keep in mind that validations for phone numbers can get fairly tricky - often different users will include dashes, parentheses, dots, etc to separate the values of the phone number, so you may either want additional validations to account for those cases or use some kind of cleaning to make sure that you're only comparing the numbers.