Spread Windows Forms 15.0
Spread Windows Forms 15.0 Product Documentation / Developer's Guide / Customizing Interaction in Cells / Using Validation / Using Validation in Cells / Using a Regular Expression Validator
In This Topic
    Using a Regular Expression Validator
    In This Topic

    You can create a regular expression validator that checks to see if a cell's value matches the specified regular expression.

    A validation error occurs if the value is not valid. You can also create an action, such as adding a backcolor to the cell, that lets the user know the value is invalid.

    Use the RegularExpressionValidator class to create the validator. Specify a notification type such as CellStyleNotify. Then use the AddValidators method to add the validator to a cell range.

    Regular Expression Validator

    Using Code

    The following example displays the invalid color if the value does not match the expression.

    Copy Code
    //The error backcolor is displayed if the value is invalid
    FarPoint.Win.Spread.CellStyleNotify cnotify = new FarPoint.Win.Spread.CellStyleNotify();
    cnotify.InvalidCellStyle.BackColor = Color.Lime;
    FarPoint.Win.Spread.RegularExpressionValidator rvalidator = new FarPoint.Win.Spread.RegularExpressionValidator();
    rvalidator.Expression = "AA";
    rvalidator.RegexOptions = System.Text.RegularExpressions.RegexOptions.IgnoreCase;
    rvalidator.NullIsValid = true;
    fpSpread1.Sheets[0].AddValidators(new FarPoint.Win.Spread.Model.CellRange(1, 1, 1, 1), rvalidator);
    Copy Code
    'The error backcolor is displayed if the value is invalid
    Dim cnotify As New FarPoint.Win.Spread.CellStyleNotify()
    cnotify.InvalidCellStyle.BackColor = Color.Lime
    Dim rvalidator As New FarPoint.Win.Spread.RegularExpressionValidator()
    rvalidator.Expression = "AA"
    rvalidator.RegexOptions = System.Text.RegularExpressions.RegexOptions.IgnoreCase
    rvalidator.NullIsValid = True
    fpSpread1.Sheets(0).AddValidators(New FarPoint.Win.Spread.Model.CellRange(1, 1, 1, 1), rvalidator)
    See Also