I use a regular expression to validate a price, but the error message appears before I finish to insert the value.
For example, I what yo insert the value "10.20", and when I get to "10." the message error is presented.
How can I avoid this message to appear until I finish to insert the all value?
Model:
[Required(ErrorMessage = "Preenchimento obrigatório.")]
[Display(Name = "Valor em €")]
[RegularExpression(@"^(?!0\d|$)\d*(\.\d{1,2})?$", ErrorMessage = "Valor inválido.")]
public decimal Valor { get; set; }
HTML:
<input data-val="true" data-val-number="The field Peso Líquido em kg must be a number." data-val-regex="Valor inválido." data-val-regex-pattern="^(?!0\d|$)\d*(\.\d{1,3})?$" data-val-required="Preenchimento obrigatório." id="PesoLiquido" name="PesoLiquido" placeholder="Ex. 10.200" type="text" value="" class="input-validation-error">
The validation is made automatically by the library jquery.validate.unobtrusive.js
Thanks