# Using the Range Validator

Learn how to use the Range Validator to check if a value is within a specified range and create validation conditions for cell ranges with the RangeValidator class.

## Content

You can use the range validator to check to see if a value is within a specified range. A validation error occurs if the value is not within the specified range. You can also create an action, such as changing the cell backcolor, that lets the user know the value is invalid.
Use the **RangeValidator** class to create the validation conditions. Specify a notification type such as [CellStyleNotify](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.CellStyleNotify.html). Then use the [AddValidators](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.AddValidators.html) method to add the validator to a cell range.
The following image uses the [CellStyleNotify](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.CellStyleNotify.html) class to change the cell backcolor when an invalid value is typed.
![Range Validator Example](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/rangevalid.png)

## Using Code

The following example sets a minimum and maximum value for the cell. A different backcolor is shown if you type an invalid value in the cell.

```csharp
FarPoint.Win.Spread.CellStyleNotify stylenotify = new FarPoint.Win.Spread.CellStyleNotify();
stylenotify.InvalidCellStyle.BackColor = Color.Aquamarine;
FarPoint.Win.Spread.RangeValidator rvalid = new FarPoint.Win.Spread.RangeValidator();
rvalid.MaxValue = 10;
rvalid.MinValue = 0;
rvalid.Actions.Add(stylenotify);
fpSpread1.Sheets[0].AddValidators(new FarPoint.Win.Spread.Model.CellRange(1, 1, 1, 1), rvalid);
```

```vbnet
Dim stylenotify As New FarPoint.Win.Spread.CellStyleNotify()
stylenotify.InvalidCellStyle.BackColor = Color.Aquamarine
Dim rvalid As New FarPoint.Win.Spread.RangeValidator()
rvalid.MaxValue = 10
rvalid.MinValue = 0
rvalid.Actions.Add(stylenotify)
fpSpread1.Sheets(0).AddValidators(New FarPoint.Win.Spread.Model.CellRange(1, 1, 1, 1), rvalid)
```

## See Also

[Using a Cell Comparison Validator](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell/spwin-cellvalid/spwin-cellvalidation/spwin-cellcomparevalidator)
[Using a Character Format Validator](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell/spwin-cellvalid/spwin-cellvalidation/spwin-cellcharformatv)
[Using a String Comparison Validator](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell/spwin-cellvalid/spwin-cellvalidation/spwin-cellcomparestring)
[Using a Value Comparison Validator](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell/spwin-cellvalid/spwin-cellvalidation/spwin-cellcomparevalue)
[Using an Encoding Validator](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell/spwin-cellvalid/spwin-cellvalidation/spwin-cellencodingvalid)
[Using the Exclude List Validator](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell/spwin-cellvalid/spwin-cellvalidation/spwin-cellexcludevalidator)
[Using the Include List Validator](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell/spwin-cellvalid/spwin-cellvalidation/spwin-cellincludevalidate)
[Using a Pair Validator](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell/spwin-cellvalid/spwin-cellvalidation/spwin-cellpairvalidate)
[Using a Regular Expression Validator](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell/spwin-cellvalid/spwin-cellvalidation/spwin-cellregexpression)
[Using a Required Field Validator](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell/spwin-cellvalid/spwin-cellvalidation/spwin-cellrequiredvalid)
[Using a Required Type Validator](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell/spwin-cellvalid/spwin-cellvalidation/spwin-cellrequiretypev)
[Using a Surrogate Character Validator](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell/spwin-cellvalid/spwin-cellvalidation/spwin-cellsurrogate)
[Using a Text Length Validator](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell/spwin-cellvalid/spwin-cellvalidation/spwin-celltextlvalid)