Skip to content

Static methods ​

Without having to initialize any AutoNumeric object, you can directly use the static AutoNumeric class functions.

Info

Some of those functions can be used in Web Workers.

Get ​

MethodDescriptionCall example
getAutoNumericElementReturn the AutoNumeric object that manages the given DOM elementAutoNumeric.getAutoNumericElement(domElement)
AutoNumeric.getAutoNumericElement('#theInput')
getDefaultConfigReturn the default autoNumeric settingsAutoNumeric.getDefaultConfig()
getFormattedReturn the formatted string from the given DOM element or query selector.
This can accept a callback that is passed the result of getFormatted and a reference to the AutoNumeric object.
AutoNumeric.getFormatted(domElement, callback);
AutoNumeric.getFormatted('#theInput')
getLocalizedReturn the localized unformatted number as a string from the given DOM element or query selector.
This can accept a callback that is passed the result of getLocalized and a reference to the AutoNumeric object.
AutoNumeric.getLocalized(domElement, forcedOutputFormat, callback);
AutoNumeric.getLocalized('#theInput')
getNumberReturn the unformatted number as a number from the given DOM element or query selector (The same warnings got the non-static getNumber method applies here too).
This can accept a callback that is passed the result of getNumber and a reference to the AutoNumeric object.
AutoNumeric.getNumber(domElement, callback);
AutoNumeric.getNumber('#theInput')
getNumericStringReturn the unformatted number as a string from the given DOM element or query selector.
This can accept a callback that is passed the result of getNumericString and a reference to the AutoNumeric object.
AutoNumeric.getNumericString(domElement, callback)
AutoNumeric.getNumericString('#theInput')
getPredefinedOptionsReturn all the predefined options in one objectAutoNumeric.getPredefinedOptions()
getPredefinedOptionsReturn a specific pre-defined language option objectAutoNumeric.getPredefinedOptions().French

Set ​

MethodDescriptionCall example
localizeAndSetUnformat and localize the domElement value with the given options and returns the localized value as a string. This function does update that element value with the newly localized value in the process.AutoNumeric.localizeAndSet(domElement, { options });
formatAndSetFormat the domElement value with the given options and returns the formatted value as a string. This function does update that element value with the newly formatted value in the process.AutoNumeric.formatAndSet(domElement, { options });
reformatAndSetRecursively format all the autoNumeric-managed elements that are a child to the referenceToTheDomElement element given as a parameter (this is usually the parent <form> element), with the settings of each AutoNumeric elements.AutoNumeric.reformatAndSet(referenceToTheDomElement);
setSet the given value on the AutoNumeric object that manages the given DOM element, if any. Returns null if no AutoNumeric object is found, otherwise returns the AutoNumeric object.AutoNumeric.set(domElement, 42)
AutoNumeric.set('#theInput', 42)
unformatAndSetUnformat the domElement value with the given options and returns the unformatted value as a numeric string. This function does update that element value with the newly unformatted value in the process.AutoNumeric.unformatAndSet(domElement, { options });
unformatAndSetRecursively unformat all the autoNumeric-managed elements that are a child to the referenceToTheDomElement element given as a parameter (this is usually the parent <form> element)AutoNumeric.unformatAndSet(referenceToTheDomElement);

Formatting ​

MethodDescriptionCall example
formatFormat the given number with the given options. This returns the formatted value as a string.AutoNumeric.format(12345.21, { options });
formatIdem above, but using a numeric string as the first parameterAutoNumeric.format('12345.21', { options });
formatIdem above, but you can pass as many option objects you want to this function, the latter overwriting the previous ones. This allows to correctly format currencies that have a predefined option as its base, but has been slightly modified.AutoNumeric.format('12345.21', { options1 }, { options2 });
formatIdem above, using multiple option objects in one array. This way allows for using a pre-defined option name.AutoNumeric.format('12345.21', [{ options1 }, 'euroPos', { options2 }]);
formatFormat the domElement value (or textContent) with the given options and returns the formatted value as a string. This does not update that element value.AutoNumeric.format(domElement, { options });
localizeUnformat and localize the given formatted string with the given options. This returns a string.AutoNumeric.localize('1.234,56 €', { options });
localizeIdem as above, but return the localized DOM element value. This does not update that element value.AutoNumeric.localize(domElement, { options });
unformatUnformat the given formatted string with the given options. This returns a numeric string.AutoNumeric.unformat('1.234,56 €', { options });
unformatIdem above, but you can pass as many option objects you want to this function, the latter overwriting the previous ones. This allows to correctly unformat currencies that have a predefined option as its base, but has been slightly modified.AutoNumeric.unformat('241800,02 €', AutoNumeric.getPredefinedOptions().French, { digitGroupSeparator: AutoNumeric.options.digitGroupSeparator.noSeparator });
unformatIdem above, using multiple option objects in one array. This way allows for using a pre-defined option name.AutoNumeric.unformat('1.234,56 €', [{ options1 }, 'euroPos', { options2 }]);
unformatUnformat the domElement value with the given options and returns the unformatted numeric string. This does not update that element value.AutoNumeric.unformat(domElement, { options });

Tests and miscellaneous ​

MethodDescriptionCall example
areSettingsValidReturn true in the settings are validAutoNumeric.areSettingsValid({ options })
isManagedByAutoNumericReturn true if the given DOM element (or selector string) has an AutoNumeric object that manages it.AutoNumeric.isManagedByAutoNumeric(domElement);
AutoNumeric.isManagedByAutoNumeric('#theInput');
mergeOptionsAccepts an array of option objects and / or pre-defined option names, and return a single option object where the latter element overwrite the settings from the previous onesAutoNumeric.mergeOptions(['euro', { currencySymbol: '#' }]);
testTest if the given DOM element (or selector string) is already managed by AutoNumeric (if it is initialized)AutoNumeric.test(domElement);
AutoNumeric.test('#theInput');
validateCheck if the given option object is valid, and that each option is valid as well. This throws an error if it's not.AutoNumeric.validate({ options })
versionReturn the current AutoNumeric version number (for debugging purpose)AutoNumeric.version();