# FDataValidation

> Language fallback: requested `ko-KR`; content is `en-US`.

- Human documentation: [https://docs.univer.ai/ko-KR/reference/facade/data-validation](https://docs.univer.ai/ko-KR/reference/facade/data-validation)

- Agent Markdown: [https://docs.univer.ai/ko-KR/reference/facade/data-validation.md](https://docs.univer.ai/ko-KR/reference/facade/data-validation.md)

- Requested language: `ko-KR`

- Content language: `en-US`

- Documentation version: `1.0.4`

- Source: [facade/data-validation.mdx](https://github.com/dream-num/documentation/blob/dev/content/reference/facade/data-validation.mdx)

---

## Access

Access through:

* [`FDataValidationBuilder.build()`](https://docs.univer.ai/ko-KR/reference/facade/data-validation-builder.md#build)
* [`FRange.getDataValidation()`](https://docs.univer.ai/ko-KR/reference/facade/range.md#getdatavalidation)
* [`FRange.getDataValidations()`](https://docs.univer.ai/ko-KR/reference/facade/range.md#getdatavalidations)
* [`FWorksheet.getDataValidations()`](https://docs.univer.ai/ko-KR/reference/facade/worksheet.md#getdatavalidations)
* [`FWorksheet.getDataValidation()`](https://docs.univer.ai/ko-KR/reference/facade/worksheet.md#getdatavalidation)

## Setup

Register [`@univerjs/sheets-data-validation`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs/sheets-data-validation.md) or a preset that includes it. In plugin mode, import `@univerjs/sheets-data-validation/facade`. Additional methods below require their listed plugin packages. See [Facade setup](https://docs.univer.ai/ko-KR/guides/sheets/getting-started/facade.md).

## `@univerjs/sheets-data-validation`

### `FDataValidation.copy`

Creates a new instance of FDataValidationBuilder using the current rule object

```typescript
copy(): FDataValidationBuilder
```

**Returns**

A new FDataValidationBuilder instance with the same rule configuration

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const fRange = fWorksheet.getRange('A1:B10')
const rule = univerAPI
  .newDataValidation()
  .requireNumberBetween(1, 10)
  .setOptions({
    allowBlank: true,
    showErrorMessage: true,
    error: 'Please enter a number between 1 and 10',
  })
  .build()
fRange.setDataValidation(rule)

const builder = fRange.getDataValidation().copy()
const newRule = builder
  .requireNumberBetween(1, 5)
  .setOptions({
    error: 'Please enter a number between 1 and 5',
  })
  .build()
fRange.setDataValidation(newRule)
```

**Types:** [`FDataValidationBuilder`](https://docs.univer.ai/ko-KR/reference/facade/data-validation-builder.md)

**Package:** [`@univerjs/sheets-data-validation`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs/sheets-data-validation.md) · [Type definitions](https://unpkg.com/@univerjs/sheets-data-validation/lib/types/facade/f-data-validation.d.ts)

### `FDataValidation.delete`

Delete the data validation rule from the worksheet

```typescript
delete(): boolean
```

**Returns**

true if the rule is deleted successfully, false otherwise

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')

// Create a new data validation rule that requires a number equal to 20 for the range A1:B10
const fRange = fWorksheet.getRange('A1:B10')
const rule = univerAPI.newDataValidation().requireNumberEqualTo(20).build()
fRange.setDataValidation(rule)

// Delete the data validation rule
fRange.getDataValidation().delete()
```

**Package:** [`@univerjs/sheets-data-validation`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs/sheets-data-validation.md) · [Type definitions](https://unpkg.com/@univerjs/sheets-data-validation/lib/types/facade/f-data-validation.d.ts)

### `FDataValidation.getAllowInvalid`

Gets whether invalid data is allowed based on the error style value

```typescript
getAllowInvalid(): boolean
```

**Returns**

true if invalid data is allowed, false otherwise

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const rules = fWorksheet.getDataValidations()
rules.forEach((rule) => {
  console.log(rule, rule.getAllowInvalid())
})
```

**Package:** [`@univerjs/sheets-data-validation`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs/sheets-data-validation.md) · [Type definitions](https://unpkg.com/@univerjs/sheets-data-validation/lib/types/facade/f-data-validation.d.ts)

### `FDataValidation.getApplied`

Gets whether the data validation rule is applied to the worksheet

```typescript
getApplied(): boolean
```

**Returns**

true if the rule is applied, false otherwise

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const rules = fWorksheet.getDataValidations()
rules.forEach((rule) => {
  console.log(rule, rule.getApplied())
})

const fRange = fWorksheet.getRange('A1:B10')
console.log(fRange.getDataValidation()?.getApplied())
```

**Package:** [`@univerjs/sheets-data-validation`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs/sheets-data-validation.md) · [Type definitions](https://unpkg.com/@univerjs/sheets-data-validation/lib/types/facade/f-data-validation.d.ts)

### `FDataValidation.getCriteriaType`

Gets the data validation type of the rule

```typescript
getCriteriaType(): DataValidationType | string
```

**Returns**

The data validation type

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const rules = fWorksheet.getDataValidations()
rules.forEach((rule) => {
  console.log(rule, rule.getCriteriaType())
})
```

**Types:** [`DataValidationType`](https://unpkg.com/@univerjs/core/lib/types/types/enum/data-validation-type.d.ts)

**Package:** [`@univerjs/sheets-data-validation`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs/sheets-data-validation.md) · [Type definitions](https://unpkg.com/@univerjs/sheets-data-validation/lib/types/facade/f-data-validation.d.ts)

### `FDataValidation.getCriteriaValues`

Gets the values used for criteria evaluation

```typescript
getCriteriaValues(): [string | undefined, string | undefined, string | undefined]
```

**Returns**

An array containing the operator, formula1, and formula2 values

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const rules = fWorksheet.getDataValidations()
rules.forEach((rule) => {
  console.log(rule)
  const criteriaValues = rule.getCriteriaValues()
  const [operator, formula1, formula2] = criteriaValues
  console.log(operator, formula1, formula2)
})
```

**Package:** [`@univerjs/sheets-data-validation`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs/sheets-data-validation.md) · [Type definitions](https://unpkg.com/@univerjs/sheets-data-validation/lib/types/facade/f-data-validation.d.ts)

### `FDataValidation.getHelpText`

Gets the help text information, which is used to provide users with guidance and support

```typescript
getHelpText(): string | undefined
```

**Returns**

Returns the help text information. If there is no error message, it returns an undefined value

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const fRange = fWorksheet.getRange('A1:B10')
const rule = univerAPI
  .newDataValidation()
  .requireNumberBetween(1, 10)
  .setOptions({
    allowBlank: true,
    showErrorMessage: true,
    error: 'Please enter a number between 1 and 10',
  })
  .build()
fRange.setDataValidation(rule)
console.log(fRange.getDataValidation().getHelpText()) // 'Please enter a number between 1 and 10'
```

**Package:** [`@univerjs/sheets-data-validation`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs/sheets-data-validation.md) · [Type definitions](https://unpkg.com/@univerjs/sheets-data-validation/lib/types/facade/f-data-validation.d.ts)

### `FDataValidation.getRanges`

Gets the ranges to which the data validation rule is applied

```typescript
getRanges(): FRange[]
```

**Returns**

An array of FRange objects representing the ranges to which the data validation rule is applied

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const rules = fWorksheet.getDataValidations()
rules.forEach((rule) => {
  console.log(rule)
  const ranges = rule.getRanges()
  ranges.forEach((range) => {
    console.log(range.getA1Notation())
  })
})
```

**Types:** [`FRange`](https://docs.univer.ai/ko-KR/reference/facade/range.md)

**Package:** [`@univerjs/sheets-data-validation`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs/sheets-data-validation.md) · [Type definitions](https://unpkg.com/@univerjs/sheets-data-validation/lib/types/facade/f-data-validation.d.ts)

### `FDataValidation.getSheetId`

Gets the sheet ID of the worksheet

```typescript
getSheetId(): string | undefined
```

**Returns**

The sheet ID of the worksheet

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const fRange = fWorksheet.getRange('A1:B10')
console.log(fRange.getDataValidation().getSheetId())
```

**Package:** [`@univerjs/sheets-data-validation`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs/sheets-data-validation.md) · [Type definitions](https://unpkg.com/@univerjs/sheets-data-validation/lib/types/facade/f-data-validation.d.ts)

### `FDataValidation.getUnitId`

Gets the unit ID of the workbook

```typescript
getUnitId(): string | undefined
```

**Returns**

The unit ID of the workbook

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const fRange = fWorksheet.getRange('A1:B10')
console.log(fRange.getDataValidation().getUnitId())
```

**Package:** [`@univerjs/sheets-data-validation`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs/sheets-data-validation.md) · [Type definitions](https://unpkg.com/@univerjs/sheets-data-validation/lib/types/facade/f-data-validation.d.ts)

### `FDataValidation.rule`

The underlying validation rule data. Use the Facade setters to update a rule attached to a worksheet.

```ts
rule: IDataValidationRule
```

**Types:** [`IDataValidationRule`](https://unpkg.com/@univerjs/core/lib/types/types/interfaces/i-data-validation.d.ts)

**Package:** [`@univerjs/sheets-data-validation`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs/sheets-data-validation.md) · [Type definitions](https://unpkg.com/@univerjs/sheets-data-validation/lib/types/facade/f-data-validation.d.ts)

### `FDataValidation.setCriteria`

Set Criteria for the data validation rule

```typescript
setCriteria(type: DataValidationType, values: [DataValidationOperator, string, string], allowBlank?: boolean): FDataValidation
```

**Parameters**

* `type` — Required. The type of data validation criteria
* `values` — Required. An array containing the operator, formula1, and formula2 values
* `allowBlank` — Optional. Default: `true`. Whether to allow blank values

**Returns**

The current instance for method chaining

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')

// Create a new data validation rule that requires a number equal to 20 for the range A1:B10
const fRange = fWorksheet.getRange('A1:B10')
const rule = univerAPI.newDataValidation().requireNumberEqualTo(20).build()
fRange.setDataValidation(rule)

// Change the rule criteria to require a number between 1 and 10
fRange
  .getDataValidation()
  .setCriteria(univerAPI.Enum.DataValidationType.DECIMAL, [
    univerAPI.Enum.DataValidationOperator.BETWEEN,
    '1',
    '10',
  ])
```

**Types:** [`FDataValidation`](https://docs.univer.ai/ko-KR/reference/facade/data-validation.md) · [`DataValidationType`](https://unpkg.com/@univerjs/core/lib/types/types/enum/data-validation-type.d.ts) · [`DataValidationOperator`](https://unpkg.com/@univerjs/core/lib/types/types/enum/data-validation-operator.d.ts)

**Package:** [`@univerjs/sheets-data-validation`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs/sheets-data-validation.md) · [Type definitions](https://unpkg.com/@univerjs/sheets-data-validation/lib/types/facade/f-data-validation.d.ts)

### `FDataValidation.setOptions`

Set the options for the data validation rule

```typescript
setOptions(options: Partial<IDataValidationRuleOptions>): FDataValidation
```

**Parameters**

* `options` — Required. The options to set for the data validation rule

**Returns**

The current instance for method chaining

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')

// Create a new data validation rule that requires a number equal to 20 for the range A1:B10
const fRange = fWorksheet.getRange('A1:B10')
const rule = univerAPI.newDataValidation().requireNumberEqualTo(20).build()
fRange.setDataValidation(rule)

// Supplement the rule with additional options
fRange.getDataValidation().setOptions({
  allowBlank: true,
  showErrorMessage: true,
  error: 'Please enter a valid value',
})
```

**Types:** [`FDataValidation`](https://docs.univer.ai/ko-KR/reference/facade/data-validation.md) · [`Partial`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts) · [`IDataValidationRuleOptions`](https://unpkg.com/@univerjs/core/lib/types/types/interfaces/i-data-validation.d.ts)

**Package:** [`@univerjs/sheets-data-validation`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs/sheets-data-validation.md) · [Type definitions](https://unpkg.com/@univerjs/sheets-data-validation/lib/types/facade/f-data-validation.d.ts)

### `FDataValidation.setRanges`

Set the ranges to the data validation rule

```typescript
setRanges(ranges: FRange[]): FDataValidation
```

**Parameters**

* `ranges` — Required. New ranges array

**Returns**

The current instance for method chaining

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')

// Create a new data validation rule that requires a number equal to 20 for the range A1:B10
const fRange = fWorksheet.getRange('A1:B10')
const rule = univerAPI.newDataValidation().requireNumberEqualTo(20).build()
fRange.setDataValidation(rule)

// Change the range to C1:D10
const newRuleRange = fWorksheet.getRange('C1:D10')
fRange.getDataValidation().setRanges([newRuleRange])
```

**Types:** [`FDataValidation`](https://docs.univer.ai/ko-KR/reference/facade/data-validation.md) · [`FRange`](https://docs.univer.ai/ko-KR/reference/facade/range.md)

**Package:** [`@univerjs/sheets-data-validation`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs/sheets-data-validation.md) · [Type definitions](https://unpkg.com/@univerjs/sheets-data-validation/lib/types/facade/f-data-validation.d.ts)
