jquery money masking input with negative integer o

2019-08-18 17:06发布

问题:

I am trying to mask input only with optional negative or positive integers. I tried using

jQuery(function($){
   $.mask.definitions['~']='[-]?';
   $("#eyescript").mask("~?999999999");
});

but this is allowing any character at the first place. (Eg: f12, -12, +12, /12, etc..)

I want the user to strictly use only '-' or any number in the first position.

How can I do this?

回答1:

Actually, I think I found the answer. Added one integer or negative sign as optional and reduced one 9 from the mask to satisfy the requirement.

jQuery(function($){ $.mask.definitions['~']='[0-9-?]'; $("#eyescript").mask("~?99999999"); });