I am trying to create a jquery validation for number.
It should allow 4 digit first and then after decimal point it should allow 1 digit.
For decimal my code is working fine:
$.validator.addMethod('Decimal', function(value, element) {
return this.optional(element) || /^[0-9,\d{4}]+(\.\d{0,1})?$/.test(value);
}, "Please enter a correct number, format xxxx.X");
I may be making mistake in regular expression.
For exactly NNNN.N (1234.5) use:
For optional .N (1234 1234. 1234.5) go with:
For numbers up to size of NNNN.N (1 .5 12.5 123. 1234 1234.5) go with:
And if you want to allow +/- at the beginning, then replace
^with^[-+]?.