Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Validation] Add "Integer" rule #561

Open
kiaking opened this issue Oct 25, 2024 · 2 comments
Open

[Validation] Add "Integer" rule #561

kiaking opened this issue Oct 25, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@kiaking
Copy link
Member

kiaking commented Oct 25, 2024

Add validation rule to validate the given number is integer (no decimals). Vuelidate has this built in validator, but I guess it would be easy to implement our own with Number.isInteger(v).

@kiaking kiaking added the enhancement New feature or request label Oct 25, 2024
@cuebit
Copy link
Member

cuebit commented Oct 25, 2024

What do you mean by no decimals? Number.isInteger will still recognise e.g. 1.0 (but not 1.1, etc) as a valid integer.

Isn't this essentially positiveInteger?

That said, positiveInteger and negativeInteger are identical. Not sure if this was a heuristic choice...

@kiaking
Copy link
Member Author

kiaking commented Oct 25, 2024

Ah yeah we had positiveInteger... 🤔

What do you mean by no decimals? Number.isInteger will still recognise e.g. 1.0 (but not 1.1, etc) as a valid integer.

Good point. I think we can accept 1.0. This rule should verify that the value can be treated as integer. In our case, in Go for example.

func main() {
	var n int
	n = 1
	n = 1.0 // This works
	n = 1.1 // This is not

	fmt.Printf("%d", n)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants