> For the complete documentation index, see [llms.txt](https://wajahatkarim.gitbook.io/easyvalidation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wajahatkarim.gitbook.io/easyvalidation/usage/create-custom-rules.md).

# Create Custom Rules

Along with [30+ built-in rules](/easyvalidation/usage/built-in-rules.md), 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()
```
