Where my problem lies is if a user writes 200 then it makes a mistake.
But that error only because I have for example written 200.
I have tried different things that have led to it approving only the number 200 if it is.
My Models:
[Required(ErrorMessage = "Money")]
[RegularExpression(@"\d+(\.\d{1,2})?", ErrorMessage = "Error")]
[Range(0, 99999.99, ErrorMessage ="Error")]
[DataType(DataType.Text)]
[Display(Name = "Money")]
public string Pay { get; set; }
in my CompaniesController i get the value from "Pay"
decimal PayValue = model.Pay.ToString().PayValue();
And thus, in PayValue, I have done so that it divides the price in proportion to having to throw "," in between two numbers.
public static decimal PayValue(this string str)
{
string[] pay;
pay = str.ToString().Split('.');
return Convert.ToDecimal(pay[0] + "," + pay[1]);
}
Here I would like it to run through and be successful.
- Error here: 200
- Error here: 20000
Thus, I would like if a customer writes the two numbers oven over then it must itself add ,00 only if nothing ,00 is add after the whole number.
Code fails if I only write 200, What I want it to be is that it must go through and even add ,00 after the number.