Wijmo provides a format function library that allows you to use formatting and masking functions outside of the input widgets, so that you can have matching input and output routines. We provide three types of formatting functions: Date, Mask, and Number. Each formatting function has a value parameter, plus an optional format (or type) parameter and another optional parameter. See each type of formatting below for further details.
Date formatting takes three parameters. Only the value parameter is required.
string $.wijinputcore.format(Date value, string format, IDateOptions options);
Parameter Name | Type | Description |
---|---|---|
value | Date | The value to format. |
format | string | The formatting string to apply to the value. Default value: d For the full list of supported format keywords, see Date Format Keywords. |
options | IDateOptions | Set any of a number of available options to format the date. For the full list of available options, see the list of Fields in IDateOptions. |
Date Format Examples |
Copy Code |
---|---|
$.wijinputcore.format(new Date(2013,8,12)); //returns: "9/12/2013" $.wijinputcore.format(new Date(2013,8,12), "yyyy/MM/dd"); //returns: "2013/09/12" $.wijinputcore.format(new Date(2013,8,12),{culture: "ja-JP"}); //returns: "2013/09/12" $.wijinputcore.format(new Date(2013,8,12,23,22,33), "tt hh:mm:ss", {culture: "ja-JP"}); //returns: "午後 11:22:33" $.wijinputcore.format(new Date(2013,8,12,24,12,12), "HH:mm:ss", {midnightAs0: true}); //returns: "00:12:12" |
Mask formatting takes three parameters. Only the value parameter is required.
string $.wijinputcore.format(string value, string format, IMaskOptions options);
Parameter Name | Type | Description |
---|---|---|
value | string | The value to format. |
format | string | The formatting string to apply to the value. Default value: "" For the full list of supported format keywords, see Mask Format Keywords. |
options | IMaskOptions | Set any of a number of available options to format the mask. For the full list of available options, see the list of Fields in IMaskOptions. |
Mask Format Examples |
Copy Code |
---|---|
$.wijinputcore.format("1234567", "999-9999", {autoConvert: true}); //returns: "123-4567" $.wijinputcore.format("1234567", "999-9999", {autoConvert: false}); //returns: " " |
Number formatting takes three parameters. Only the value parameter is required.
string $.wijinputcore.format(Number value, string type, INumberOptions options);
Parameter Name | Type | Description |
---|---|---|
value | Number | The value to format. |
type | string | The formatting string to apply to the value. Default value: numeric Valid values: currency, numeric, or percent |
options | INumberOptions | Set any of a number of available options to format the number. For the full list of available options, see the list of Fields in INumberOptions. |
Number Format Examples |
Copy Code |
---|---|
$.wijinputcore.format(12345); //returns: "12345.00" $.wijinputcore.format(12345, "numeric", {decimalPlaces:3}); //returns: "12345.000" $.wijinputcore.format(12345, "percent"); //returns: "12345.00 %" $.wijinputcore.format(12345, "currency"); //returns: "$12345.00" $.wijinputcore.format(12345, "currency", {culture: "ja-JP"}); //returns: "¥12345.00" $.wijinputcore.format(12345, "numeric", {positivePrefix: "+", negativePrefix: "-"}); //returns: "+12345.00" |