I have a list question named members that records the full name of the household member. (John Doe). I want to validate whether the full name is being provided and not the first or last name only. (I know persons like Madonna goes by one name only).
Can you provide some basic syntax that will assist with this? Can I count the number of words in the field and if less than 2, for example, trigger a warning message?
Thanks in advance.
Use a validation condition for members:
condition: self.All(line => line.Text.Split(’ ').Length > 1)
message: “Please provide first and last name!”
Good day klaus
The code provided worked fine once I removed the ’ ’ from within the brackets. Thank you very much for your prompt response.
- The validation condition is ok for this, but with a help of a microscope one can see that the quotes in the condition are distorted:
This could be the result of copying through some buffer, or typing on a phone, or something else.
When writing a C# syntax, use straight single quotes like shown below:
when you need to indicate a particular character (as opposed to double-quotes when need to indicate a string).
- The validation condition however is not going to count the words in general situation. While it works in the specific case, please note that:
- it relies on the actual (though not entirely obvious) behavior of Survey Solutions trimming the content of text answers (which may or may not be continued in the future versions);
- it will no longer be correct if you need for example 3 words minimum (changing 1 into 2 in the condition will not be enough in this case), for this example string:
(note, there are 2 spaces between Foo and Bar).
None of these points is an unsolvable problem, but more importantly answering the question (“…count the number of words…”) precisely requires a precise definition of what a ‘word’ really is.
Sergiy, noted with thanks.
@sergiy; you are right, I copied from Designer and pasted into the message.