Last post Sep 26, 2015 01:04 PM by jkjhse
Sep 26, 2015 09:17 AM|mdehghani|LINK
Hi everyone.. I currently have a textbox input that receives numbers from users but with commas.. for example: 10,000,000
it seems obvious that I couldn't validate this input to make sure it's a numeral using the validation helper . so I decided to first trim the commas out of the input using:
var myinput="";myinput= new String(Request.Form["myinput"].Where(Char.IsLetterOrDigit).ToArray());
and then do some manual validation like:
if (int.TryParse(myinput, out res))
now I was wondering whether the procedure above is good practice for validating and how can I validate larger numerals rather than being limited to int?
Sep 26, 2015 09:47 AM|PatriceSc|LINK
The point is that parsing a number (or a date) depends on the particular country convention which is in currently in use. See
https://msdn.microsoft.com/en-us/library/bz9tc508.aspx for how to define it (once for all in the web.config or dynamically depending on user preference). If using the country convention you
(or the user) really want you shouldn't have any more to alter the user input before trying to validate it.
Sep 26, 2015 01:04 PM|jkjhse|LINK
You have many options.
Validator.Required("Make sure you say how many you want"),
Validator.Range(1,4, "Must be between 1 and 4")
myinput = Request["number"]
ModelState.AddFormError("There are some errors with your submission");
//Input Field Like this