Here are a selection of RegExr validation scripts to use with error messages.
var qnTxt : String = f(CurrentForm()).get();if(!regexPattern.test(qnTxt))
{
RaiseError();
SetQuestionErrorMessage(2057,”The reference must be 8 characters in length in the format nn/nnnnn”);
}
If using this validation for a open text list the masking would look like
Check for a Name
Will not allow string to start with any character other than alphanumeric. Will allow – and ‘
var qnTxt : String = f(CurrentForm()).get();if(!regexPattern.test(qnTxt))
{
RaiseError();
SetQuestionErrorMessage(2057,”The field must be in the correct name format”);
}
Check for only letters, no spaces or special characters
var regexPattern = /^[a-zA-Z]([a-zA-Z])+$/
var qnTxt : String = f(CurrentForm()).get();
if(!regexPattern.test(qnTxt))
{
RaiseError();
SetQuestionErrorMessage(2057,”The field must be in the correct name format”);
}
Check for less than 2 digits in length AKA less than 100% for a open string field
var regexPattern = /^\d{2}$/;;
var qnTxt : String = f(‘qnr_detailsfrompurchaser_100_2_other’).get();
if(!regexPattern.test(qnTxt))
{
RaiseError();
SetQuestionErrorMessage(2057,”Must be less than 100, not including %”);
}