Home Reference Source
public class | source

NumberMask

NumberMask

A javascript implementation for BBj numbers masking

Static Method Summary

Static Public Methods
public static

mask(number: Number, mask: String, groupingSeparator: String, decimalSeparator: String, forceTrailingZeros: Boolean, loose: Boolean, ignoreFillChar: Boolean, trimSpaces: Boolean, floatSpecialChars: Boolean): String

Mask the given number with the given mask according to BBj rules

Static Public Methods

public static mask(number: Number, mask: String, groupingSeparator: String, decimalSeparator: String, forceTrailingZeros: Boolean, loose: Boolean, ignoreFillChar: Boolean, trimSpaces: Boolean, floatSpecialChars: Boolean): String source

Mask the given number with the given mask according to BBj rules

Params:

NameTypeAttributeDescription
number Number

the number to format

mask String

the mask to use for formatting

groupingSeparator String
  • optional
  • default: ,

a char which will be used as a grouping separator

decimalSeparator String
  • optional
  • default: .

a char which will be used as a decimal separator

forceTrailingZeros Boolean
  • optional
  • default: false

Affects the output by switching the way a mask with "#" characters in the trailing positions is filled. for example, the function NumberMask.mask(.10:"#.##") returns .10 instead of .1

loose Boolean
  • optional
  • default: true

when true , errors will be ignored and the method will try at apply the mask anyway , otherwise it will stop at first error and throw it.

ignoreFillChar Boolean
  • optional
  • default: false

when true , then the fill char will always be an empty space event if the mask start with a *

trimSpaces Boolean
  • optional
  • default: false

When true , the final masked value will not contain any spaces

floatSpecialChars Boolean
  • optional
  • default: true

When true , then if any of "-", "+", "$", and "(". characters is present in the mask, the first one encountered will be moved to the last position where a "#" or "," was replaced by the fill character. If no such position exists, the float character is left where it

Return:

String

the masked number

Throw:

MaskError

only if loose is disabled