Validation Rules Forbidding Double, Leading, & Trailing Spaces; 200C & U200B
We have an interest in ensuring that our data are highly uniform and do not contain some hard-to-spot elements. I’ve made some attempts at scripting validation rules that would prevent certain types of problems and would appreciate any help that the data community here may be able to provide.
1. Rule Preventing Double Spaces
I’ve attemped to apply this validation rule that should prevent double spaces and had no luck. If you would have any input on what I could change to make it work, please, I would appreciate that.
rule {
given {
longDescription=attributes.'Long Description'?.first()
}
when {
isNotEmpty(longDescription)
}
then {
!contains(longDescription, /\s{2}/, \
message: "The Long Description of the Asset ${name} in domain \
${vocabulary.name} should not contain two whitespace characters.")
}
}
2. Validation Rules Preventing Leading and Trailing Spaces
Based on the validation script examples from the documentation, I’m not really sure on where to start with preventing leading and trailing spaces. While leading spaces are elementary to detect in Excel, nonetheless, I would appreciate anyone’s input if they have written one or more validation rules detecting leading spaces and/or trailing spaces.
3. Validation Rule(s) Preventing Unicode 200C and Unicode U200B
Unicode character 200C, the “No-Width Optional Break”; and U200B, the “Zero Width Non-Joiner” have shown up in our domains due to copy-pastes performed from web portals. Based on a reading of this Stack Overflow post, I was hopeful that the following basic outline would help us prevent these characters but the script is having no detection capability.
rule {
given {
longDescription = attributes.'Long Description'
}
when {
isNotEmpty (longDescription)
}
then {
!contains(longDescription, /\\p{Cf}/,\
message: "The asset ${name} in domain \
${vocabulary.name} must have a \
Long Description without formatting characters.")
}
}
I usually like to come to the table here with more I’m sure works, but, given that I can imagine these types of validation rule to be of larger interest, I figured I would run this by folks relatively empty-handed. As always, thanks for whatever insights you may be able to provide.
Young Wook Baek
·3 years ago · EditedHi @tyler.bass
containsmethod takes a string and a substring per documentation.Please also note that updating string attribute values on the UI directly will insert
<0xa0>(No-Break Space) character when you add multiple spaces.1. Rule Preventing Double Spaces
You can use the substring
' 'instead of a regex. Also, the message will only display if there are no double spaces (valid cases) since we are negating thecontainsmethod, so in this case, the message should be a general message, not an error message if you want to use it.2. Validation Rules Preventing Leading and Trailing Spaces
You can use a logical expression to handle this.
3. Validation Rule(s) Preventing Unicode 200C and Unicode U200B
You can use
matchesmethod for specifying a regex. The following rule should detect the “invisible formatting indicator” in theDefinitionattribute and invalidate an asset if found.Hope this helps.
Young Wook Baek
·3 years ago · EditedHi @tyler.bass
containsmethod takes a string and a substring per documentation.Please also note that updating string attribute values on the UI directly will insert
<0xa0>(No-Break Space) character when you add multiple spaces.1. Rule Preventing Double Spaces
You can use the substring
' 'instead of a regex. Also, the message will only display if there are no double spaces (valid cases) since we are negating thecontainsmethod, so in this case, the message should be a general message, not an error message if you want to use it.2. Validation Rules Preventing Leading and Trailing Spaces
You can use a logical expression to handle this.
3. Validation Rule(s) Preventing Unicode 200C and Unicode U200B
You can use
matchesmethod for specifying a regex. The following rule should detect the “invisible formatting indicator” in theDefinitionattribute and invalidate an asset if found.Hope this helps.
Tyler Bass
OP3 years ago · EditedNice work, Young, and thank you so much. With regard to letter case, I offer the following correction to the anti-Unicode 200C and 200B rule: