Better annotation of data for one decimal (18.2)
source link: https://www.codesd.com/item/better-annotation-of-data-for-one-decimal-18-2.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Better annotation of data for one decimal (18.2)
I have a column inside my sql server 2008 wih type of Decimal(18,2)
. But on entity framework what is the best data annotation validation I can apply to this property, inside my asp.net MVC web application ?
There is no explicit data annotation for a decimal so you need to use two separate ones to add constraints.
Two Decimal Points
[RegularExpression(@"^\d+\.\d{0,2}$")]
This regular expression will make sure that the property has at most two decimal places.
Max 18 digits
[Range(0, 9999999999999999.99)]
Assuming you aren't accepting any negative numbers. Otherwise, replace 0
with -9999999999999999.99
.
Result
[RegularExpression(@"^\d+\.\d{0,2}$")]
[Range(0, 9999999999999999.99)]
public decimal Property { get; set; }
Related Articles
Would SQLite be better than basic data for recovery on time ranges, etc.?
Annotation of data for the width of the column
save user data for one day (same day -> many user data)
Regular expression for one decimal point with a maximum of 2 digits before the decimal point
Annotations of data for validation, at least one mandatory field?
Cron Quartz Schedule to shoot every week from a specific date for one year
add specific days from a given date for one year
Annotated training data for the NER corpus
VB.Net VS 2008 validates textbox.text for one decimal place only
How to better store the data for a chatbot?
vim searches for one decimal but unbalances another number
Which way is better to pass a large list of data from one activity to another activity - Android?
Combine two MySQL tables, use data in one for the headers in the combined table
Which collection to use for one or more types of data?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK