JQuery plugin for formatting input

I want to accept values ​​in any of the following formats:

  • - $ 5
  • - $ 5.00
  • $ 5
  • $ 5.00

Is it possible to do this with Masked Input Plugin ?

If not, which plugin am I looking for?

How to specify an optional character?

The code that I still have

$.mask.definitions['~']='[ +-]';
$(".currency").mask("~$9");
+5
source share
5 answers

Here's how I would execute a validation rule:

$('.myinput').val().match(/^[+-]?\$\d(?:\.\d\d)?$/)

The problem with your template is that it is not a fixed length, so it’s hard to code in the mask, and you may run into some people giving $ 3.5, which you don’t want. With such a pattern, I think it will be difficult not to deviate from matching regular expressions.

, , , 0,99 , (, , ...).

+5
+5

, .

$(mask_id).maskMoney({showSymbol:false,decimal:'.',precision:2});

, , , .

+4

, ,

$.mask.definitions['~']='[ +-]';
$(".currency").mask("~$9?.99");
+1
$.mask.definitions['~']='[ +-]';

$( "" ) ( "~ $9.99"?);.

?

+1

All Articles