<p>Removed above code and added the custom validation function for CVV Validation </p>

<pre><code>public function validateCVV($attribute) {
    $value = $this-&gt;$attribute;
    if(!preg_match('/^[0-9]{3}$/', $value)) {
        $message = Craft::t("Oops!  Try again with a valid CVV security code on the back of your card.");
        $this-&gt;addError($attribute, $message);
    }        
}

$rules[] = ['CVC', 'validateCVV'];
</code></pre>

<p>Thank You.</p>

CC BY-SA 3.0
2016-04-06T06:48:51.567Z
2016-04-06T06:48:51.567Z
TechCare99
<p>I want to Number validation for my site, but not able to show custom validation message to user.</p>

<pre><code>       'CVV' =&gt; [
            'label'    =&gt;  'CVV Number',
            'type' =&gt; 'numerical',              
            'numberPattern'=&gt; '^[0-9]{3,3}$', 
            'min'   =&gt;  100, 
            'minLength'   =&gt;  3, 
            'max'   =&gt;  999,
            'maxLength'   =&gt;  3,
            'required' =&gt; true,
            'integerOnly'   =&gt;  true,
            'tooSmall'  =&gt;  'CVV Number is too small (minimum is 3 characters).',
            'message'  =&gt;  'CVV Number is too small (minimum is 3 characters).',
            'tooShort'  =&gt;  'CVV Number is too small (minimum is 3 characters).',
            'tooBig'  =&gt;    'CVV Number is too long (maximum is 3 characters).',
            'tooLong'  =&gt;    'CVV Number is too long (maximum is 3 characters).',                
        ],
</code></pre>

<p>I tried to set </p>

<pre><code>AttributeType::Number
</code></pre>

<p>Also. But it didn't work.
<strong>The issue:</strong> 
in the case of numbers like less than 3 characters, I am getting error message: </p>

<pre><code>CVV Number is too small (minimum is 100).
</code></pre>

<p>Please Can anyone help me to get this expected message.
Thank You.</p>

CC BY-SA 3.0
2016-03-14T17:33:17.890Z
Can you add some more context here? Is this a custom validator class you've written or is this in a `rules()` method on a model?
Brad Bell
<validation>
Custom Validation Message for numeric
# Custom Validation Message for numeric

(Asked by: username_0 on 2016-03-14)

I want to Number validation for my site, but not able to show custom validation message to user.
       'CVV' => [
            'label'    =>  'CVV Number',
            'type' => 'numerical',              
            'numberPattern'=> '^[0-9]{3,3}$', 
            'min'   =>  100, 
            'minLength'   =>  3, 
            'max'   =>  999,
            'maxLength'   =>  3,
            'required' => true,
            'integerOnly'   =>  true,
            'tooSmall'  =>  'CVV Number is too small (minimum is 3 characters).',
            'message'  =>  'CVV Number is too small (minimum is 3 characters).',
            'tooShort'  =>  'CVV Number is too small (minimum is 3 characters).',
            'tooBig'  =>    'CVV Number is too long (maximum is 3 characters).',
            'tooLong'  =>    'CVV Number is too long (maximum is 3 characters).',                
        ],

I tried to set 
AttributeType::Number

Also. But it didn't work.
The issue: 
in the case of numbers like less than 3 characters, I am getting error message: 
CVV Number is too small (minimum is 100).

Please Can anyone help me to get this expected message.
Thank You.

**Tags:** validation
> **Comments:**
> **username_1**: Can you add some more context here? Is this a custom validator class you've written or is this in a `rules()` method on a model?  

---

## 1 answers

### Answer by username_0 on 2016-04-06. Score: 1 | Accepted answer

Removed above code and added the custom validation function for CVV Validation 
public function validateCVV($attribute) {
    $value = $this->$attribute;
    if(!preg_match('/^[0-9]{3}$/', $value)) {
        $message = Craft::t("Oops!  Try again with a valid CVV security code on the back of your card.");
        $this->addError($attribute, $message);
    }        
}

$rules[] = ['CVC', 'validateCVV'];

Thank You.


---

