How can I correctly format currency using jquery?

前端 未结 7 1872
故里飘歌
故里飘歌 2020-12-13 01:16

I do not need a mask, but I need something that will format currency(in all browsers) and not allow for any letters or special char\'s to be typed. Thanks for the help

7条回答
  •  臣服心动
    2020-12-13 02:09

    Use jquery.inputmask 3.x. See demos here

    Include files:

    
    
    
    

    And code as

    $(selector).inputmask('decimal',
      { 'alias': 'numeric',
        'groupSeparator': '.',
        'autoGroup': true,
        'digits': 2,
        'radixPoint': ",",
        'digitsOptional': false,
        'allowMinus': false,
        'prefix': '$ ',
        'placeholder': '0'
      }
    );
    

    Highlights:

    • easy to use
    • optional parts anywere in the mask
    • possibility to define aliases which hide complexity
    • date / datetime masks
    • numeric masks
    • lots of callbacks
    • non-greedy masks
    • many features can be enabled/disabled/configured by options
    • supports readonly/disabled/dir="rtl" attributes
    • support data-inputmask attribute(s)
    • multi-mask support
    • regex-mask support
    • dynamic-mask support
    • preprocessing-mask support
    • value formatting / validating without input element

提交回复
热议问题