Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, everyone I am working on a vb mvc application. In my view model I have this code:

<RegularExpression("^[0-9]*$", ErrorMessage:="Please enter a whole positive number.")>
    Public Property IncludedColumns As Integer


When I try to enter for example a float (11.1) or NAN (11...) I got error messages, but not the message from the model (
ErrorMessage:="Please enter a whole positive number."
).

My question is how can I edit these messages and what should I do to receive the error message from the model?

What I have tried:

I searched in google how to edit these default messages but did not find anything.
Posted
Updated 7-Feb-19 4:27am

There are also a couple of things you could do within the View to reduce the amount of forms submitted with improper data.

1. A javascript "numbers only" function to only allow numbers within an input

2. Client side validation. Another javascript option to check the form fields prior to submission which will block submission until the fields match the rules in the function. Plenty of examples of this on google.

3. HTML5 allows more types of input fields, and can be changed to number. It can be tricky if you are using html-helpers, but something akin to this should help
HTML
@Html.TextBoxFor(m => m.YourPropertyName,  new { @type = "number", @min = "0" })
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900