---
description: This section describes how to create your own custom rules.
---

# Create Custom Rules

Along with [30+ built-in rules](built-in-rules), you can create your own custom rules very easily.&#x20;

First step is you have to create your `Rule` class by extending `BaseRule` or any other existing rule like this.

```kotlin
class HelloRule : BaseRule
{
    // add your validation logic in this method
    override fun validate(text: String) : Boolean
    {
        // Apply your validation rule logic here
        return text.contains("hello")
    }
    
    // Add your invalid check message here
    override fun getErrorMessage() : String
    {
        return "Text should contain 'hello' keyword"
    }
}
```

You can use this rule using `Validator.addRule()` method like this:

```kotlin
var myEditText = findViewById<EditText>(R.id.myEditText)
var myEditText.validator()
    .addRule(HelloRule())
    .addErrorCallback { 
        // In case of invalid, this method will be called.
        // The 'it' will be "Text should contain 'hello' keyword" message.
        myEditText.error = it
    }
    .check()
```
