Detect Mis-Keyed Form Entries
Mis-keyed variation detection identifies values that likely refer to the same person or organization but contain typos, misspellings, or inconsistent formatting—for example, John Smth instead of John Smith, or ACME Corp instead of ACME Corporation. This feature is useful for detecting human data entry mistakes before they create duplicates or bad records in CRM contacts, clinical registrations, insurance claims, or research participant records.
To implement approximate string matching in SurveyJS, register a custom asynchronous function and add an async expression validator to a question's validators array.
How This Demo Works
- The form collects contact details (full name, date of birth, email, organization).
- Each field is assigned an async function that validates its value.
- The function compares the field value against the corresponding property in an in-demo contact list using string similarity (with a short delay to simulate async work).
- If a near match is found, the function returns
false, and the field displays the validatortext.
Try values like John Smth, Kathrine Brown, Sofia Martinezz, or ACME Corp.
In this demo, validators use "notificationType": "warning", so validation messages do not block form submission. To prevent the form from being submitted until the issue is resolved, use the default "error" notification type.
Connect to an API Endpoint
Replace the demo helper with a fetch call (or an equivalent call using your SDK) to compare values against your CRM, patient registry, or matching service. Call this.returnResult(boolean) when validation completes:
function isNotMisKeyedName([fullName]) {
if (!fullName) {
this.returnResult(true);
return;
}
fetch("/api/validation/miskeyed", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ field: "fullName", value: fullName })
})
.then((response) => response.json())
.then((data) => {
// data.ok === true means no problematic near-match
this.returnResult(!!data.ok);
})
.catch(() => {
this.returnResult(false);
});
}
registerFunction({
name: "isNotMisKeyedName",
func: isNotMisKeyedName,
isAsync: true
});
Add expression validators to your survey JSON, for example: "expression": "isNotMisKeyedName({fullName})". Refer to the JSON schema in the Code tab for more examples.
Expression validators use a fixed text message. If your API needs to return a personalized message with a dynamically inserted value, such as "Did you mean John Smith?", use the onServerValidateQuestions event instead. See the Double-Entry Verification and Detect Duplicate Form Records demos for examples.