Editor Validation: How to enforce integer numbers
Editor Validation: How to enforce integer numbers
I am examining the .NET Validation page and see how enforce use of a decimal number, but I don't see any examples of enforcing an integer number.
What i hope to do is something like:
.Field(new Field("Table1.Column3")
.Validator(/* number must be int; number can be null */))
Is this possible?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
So after tinkering around some more, I came up with this. I observed that because the column is defined as an
int
on the database, any decimal number is truncated -- not rounded. The behavior works as a failsafe and is better than nothing. What else do I need to ensure that the user is blocked from entering a decimal number the same way the user is blocked from entering a string?This thread from yesterday will probably be of some interest to make sure the user enters a number.
Allan
I tried that. All this code did was add up/down arrows to the text box.
If I entered a decimal number, the value was then truncated and the record updated. There was no message that an integer needed to be entered.
Looks like that's the best HTML can provide just now.
You'd need to use a validator on the server-side to determine if it is a floating point value or not and reject it if so.
The only other option on the client-side i can think of is to add a key event listener and block anything other than numbers.
Allan
I was hoping I wasn't missing something obvious. At least numeric behavior is enforced. It appears that SQL Server might be doing the truncation, so I can make sure that incorrect data types are not entered.