$.fn.autoNumeric.Strip() & $.fn.autoNumeric.Format() functions

autoNumeric() has two public functions, one that allows you to strip the string of it's format and the other is to format the string.

Back to the main page

The formatted strings are very easy to type and read, however to perform any mathematical operations all of the currency symbols, thousand separators need to be stripped and if necessary the decimal separator needs to be converted to a decimal point. This is where the strip function comes in handy, by determining the format and removing.

$.fn.autoNumeric.Strip(id, {options}) - usage guide below

  • id parameter is the id of the field to be stripped
    • The id can be a string 'id.name' or set to variable - var id = 'id.name';
    • Do not use a # sign '#id.name'
    • Do not escape Special characters 'id\\.name' - see the page on special characters
  • {options} Not recommended for the strip function

The strip function returns a string that can be set to a variable or nested within another function.

  • var name = $.fn.autoNumeric.Strip('id.name');
  • $('#id\\.name2').val($.fn.autoNumeric.Strip('id.name')); Note jQuery functions id's still require escaping.
  • $(document.getElementById( id )).val($.fn.autoNumeric.Strip('id.name'); Note: you can avoid escaping jQuery by using $( document.getElementById( id ) function.

That is all that is required for the strip function.

The Format function is practically useful if multiple fields with different formats are required. Check here for a live example of the format function populating multiple fields with different formats on page ready.

$.fn.autoNumeric.Format(id, value, {options}) - usage guide below

  • id parameter is the id of the field that contains the desired format you wish to achieve
    • The id can be a string 'id.name' or set to variable - var id = 'id.name';
    • Do not use a # sign '#id.name'
    • Do not escape Special characters 'id\\.name' - see the page on special characters
  • value parameter ( unformatted string )
    • The value can be string '123.40', or numeric 123.40. Either can be set to a variable - var value = 123.40;
    • Note: this should contain only numbers and one decimal point (full stop).
  • {options} Use with caution and remember the precedence order: defaults - options - metadata. Please see the main page option formats.

The format function returns a string that can be set to a variable or nested within another function.

  • var ??? = $.fn.autoNumeric.Format('id.name', 123.40, {options});
  • $('#id\\.name2').val($.fn.autoNumeric.Format('id.name', 123.40, {options}); Note jQuery functions id's require escaping if they contain special characters
  • $(document.getElementById( id )).val($.fn.autoNumeric.Format('id.name', 123.40); Note: you can avoid escaping by using $( document.getElementById( id ) function.
  • Special note: while the Format function id parameter needs to be a input field the selector for jQuery can be any other target selector.

That is all that is required for the Format function.

Back to the main page

Please contact me is you have any questions, comments and or suggestions at bob{@}decorplanit.com (remove brackets)