How can I make a validation rule that will accept only integer and float data?

I want to create a rule which will only accept integer or float value.
Any help would be appreciated.

You can use the Indicative number rule if you are interested only in positve float and integer values:

get rules () {
  return {
    fieldName: 'number',
  }
}  
1 Like

I know that bro but I want it to verify both integer and float number.Thanks for your reply

I think @begueradj is right. Javascript doesn’t have float as a type. You should read more about that. Please feel free to read this.

I am sorry but I think you need to read my answer again :slight_smile: @gitsakil09

This is correct ^

More in depth:
Documentation for version 7.x.x of validator states:

Validation fails when number has a negative value. You must use integer or float rules for that.

But since version 7.x.x is for Adonis 5. It is irrelevant in current case.

Most likely your validation version is 5.0.x, (used in Adonis 4) you can check it from your root package.json @adonisjs/validator version.

For version 5.x.x:

Makes sure that the value of field under validation is a valid
number. The validation will pass for floats too, since it uses typeof internally.

1 Like

Thanks for your time guyzzz.I will look into this :slight_smile: :slight_smile: