This question is locked. New answers and comments are not allowed.
Hello Telerik,
I would like to share a small tweak that I have created, that you might find useful to include in the next release.
I have created a number validator that would accept a decimal as the first character via a modification to the regular expression. This has been working great, until I added a grid to the page and started inserting data. Suddenly I would start getting the 'The value you entered isn't a number' from my numeric text fields that had values with the leading decimal point character. This took some time to identify but the telerik.grid.editing.js has its own version of unobtrusive validation, and there it defines the 'number' validator. This validator sadly doesn't allow leading decimal points.
Original regex from telerik.grid.editing.js: /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/
Change regex to: /^-?(?:\d*|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/
The change will allow for zero or more digits in front of the decimal point.
Here is the tweaked validator:
Hope this helps.
Thanks,
Igor
I would like to share a small tweak that I have created, that you might find useful to include in the next release.
I have created a number validator that would accept a decimal as the first character via a modification to the regular expression. This has been working great, until I added a grid to the page and started inserting data. Suddenly I would start getting the 'The value you entered isn't a number' from my numeric text fields that had values with the leading decimal point character. This took some time to identify but the telerik.grid.editing.js has its own version of unobtrusive validation, and there it defines the 'number' validator. This validator sadly doesn't allow leading decimal points.
Original regex from telerik.grid.editing.js: /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/
Change regex to: /^-?(?:\d*|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/
The change will allow for zero or more digits in front of the decimal point.
Here is the tweaked validator:
$.validator.addMethod('number', function (value, element) { var groupSize = $t.cultureInfo.numericgroupsize; if (groupSize) { var builder = new $t.stringBuilder(); builder.cat('^-?(?:\\d*|\\d{1,') .cat(groupSize) .cat('}(?:') .cat($t.cultureInfo.numericgroupseparator) .cat('\\d{') .cat(groupSize) .cat('})+)(?:\\') .cat($t.cultureInfo.numericdecimalseparator) .cat('\\d+)?$'); return this.optional(element) || (builder && new RegExp(builder.string()).test(value)); } return this.optional(element) || /^-?(?:\d*|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(value);});Hope this helps.
Thanks,
Igor