Basically, I'd like to enforce a text field to follow a pattern like [A-Z]{4}\s{4}\d+, to use the regex for it. (Four letters followed by 4 whitespace chars, followed by 1 or more digits
Has anyone had any luck doing this?
@AlfredBaldenweck Give this a go. I used this as the testing value
/* Arcade Constraint Rule: Checks if a field matches the pattern: - Four letters (A-Z, case-insensitive) - Four whitespace characters - One or more digits Usage: Replace $feature.Name with your actual field name. */ var value = $feature.Name; // Check if value is empty if (IsEmpty(value)) { return false; } // Check length: at least 9 (4 letters + 4 spaces + 1 digit) if (Count(value) < 9) { return false; } // Check first 4 are letters for (var i = 0; i < 4; i++) { var ch = Mid(value, i, 1); if (Find(Upper(ch), "ABCDEFGHIJKLMNOPQRSTUVWXYZ") == -1) { return false; } } // Check next 4 are whitespace for (var i = 4; i < 8; i++) { if (Mid(value, i, 1) != " ") { return false; } } // Check remaining are digits for (var i = 8; i < Count(value); i++) { var ch = Mid(value, i, 1); if (Find(ch, "0123456789") == -1) { return false; } } return true;
Not an Arcade-based solution, but the Data Reviewer extension's Regular Expression check can be used to create validation attribute rules to evaluate string formatting.
This worked pretty well, but is unfortunately more involved than I was hoping.
@JayCary 's suggestion of using Data Reviewer also worked out ok, but has its own set of drawbacks.
Dropping this link to a relevant Idea Arcade: Regular Expression Support - Esri Community to add regex to Arcade.
Thanks!
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.