Empty Strings

May 14, 2008 at 2:55 PM
This custom field doesn't allow empty values in the field. When you submit a form with an empty value in one of these fields, the following error is returned:

Failed to get value of the "MyField" column from the "Custom Regular Expression Validator" field type control. See details in log. Exception message: No expression to validate provided.

Any workarounds? I am not very familiar with building regular expressions, so I am hoping I can build something into the regular expression to allow empty strings.
Coordinator
May 15, 2008 at 11:39 PM
Edited May 16, 2008 at 12:25 AM

Hi,

Thanks for your update :o)

There was a mistake in my code regarding a non mandatory blank value. I fixed it by addind a test in my CustomRegularExpressionValidatorField.cs

// Fire the validation rule if field is not null
if (value != null && (String)value != "")
{
    CustomRegularExpressionValidatorValidationRule rule = new CustomRegularExpressionValidatorValidationRule();
    Triplet myField = new Triplet(this.GetCustomProperty("myRegEx"), value, this.GetCustomProperty("myErrorMessage"));
    ValidationResult result = rule.Validate(myField, CultureInfo.InvariantCulture);

    // Error on validation
    if (!result.IsValid)
    {
        throw new SPFieldValidationException((String)result.ErrorContent);
    }
}

return base.GetValidatedString(value);

New release is available: CustomFieldRegExValidator v1.1

May 16, 2008 at 12:29 PM
Excellent!  Thanks for the prompt fix.  This custom field is very useful.
Coordinator
May 16, 2008 at 5:54 PM
Happy to help the SharePoint community :)

ccondon wrote:
Excellent!  Thanks for the prompt fix.  This custom field is very useful.