Please see the mode below:
[RegularExpression("[0-9]", ErrorMessage = "Only numbers are allowed")]
[Range(0D, 10000000000D, ErrorMessage = "Minimum salary must be 0")]
[DisplayName("Salary")]
public decimal Salary { get; set; }
and the view below:
Html.EditorFor(model => model.FirstName, new { htmlAttributes = new { @class = "form-control" } })
If a user tries to enter a non-numeric then the number appears, however validation prevents the form from being submitted/
Websites like Confused.com have a Salary field when you are entering your details. The values entered into this field have to be numberic i.e. it is impossible to even enter a character or a minus sign i.e. if the user enters a non-character then it simply does not appear. How can I do this?
Also how can I add a £ sign to the textbox? This character should not be editable.
I have spent time looking into this. For example, I have read this question: How to force Razor to make Editorfor to input number type for float variable?