Spread for ASP.NET 13 Product Documentation
Spread for ASP.NET 13 Product Documentation / Developer's Guide / Customizing with Cell Types / Working with Editable Cell Types / Setting a Regular Expression Cell
In This Topic
    Setting a Regular Expression Cell
    In This Topic

    A regular expression cell is a cell that contains a text box that restricts the way data is entered in the cell to valid entries defined in a regular expression.

    Regular Expression Cell Type with Message

    A default error message is displayed if the user types an invalid value and tries to leave the cell.

    For details on the properties and methods for this cell type, refer to the RegExpCellType class.

    The Regular Expression cell type expects the data in the cell to be a string. If you are working with other data types, such as date-time, then you need to get the date-time input, convert it to a string for the cell in the Format override, then convert the data back to a date-time in the Parse override.

    For more information about creating regular expressions, refer to the following Microsoft web site topics:

    Using Code

    1. Define the regular expression cell type by creating an instance of the RegExpCellType class.
    2. Create a regular expression.
    3. Create a message to display to the user when expression is not valid.
    4. Apply the regular expression cell type to a cell or range of cells.

    Example

    To create a cell that restricts user input to match a regular expression, use this code.

    C#
    Copy Code
    FarPoint.Web.Spread.RegExpCellType rgex = new FarPoint.Web.Spread.RegExpCellType();
    rgex.ValidationExpression = "^\\d{3}-\\d{2}-\\d{4}$";
    rgex.ErrorMessage = "SSN (ex, 123-45-6789)";
    FpSpread1.ActiveSheetView.Cells[0, 0].CellType = rgex;
    
    VB
    Copy Code
    Dim rgex As New FarPoint.Web.Spread.RegExpCellType()
    rgex.ValidationExpression = "^\d{3}-\d{2}-\d{4}$"
    rgex.ErrorMessage = "SSN (ex, 123-45-6789)"
    FpSpread1.ActiveSheetView.Cells(0, 0).CellType = rgex
    

    Using the Spread Designer

    1. In the work area, select the cell or cells for which you want to set the cell type.
    2. Select the Home menu.
    3. Select the SetCellType icon under the CellType section.
    4. Select the cell type and any other cell properties.
    5. Select OK to close the dialog.
    6. Click Apply and Exit to close the Spread Designer.
    See Also