jquery money masking input with negative integer o

2019-08-18 17:33发布

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条回答
何必那么认真
2楼-- · 2019-08-18 17:48

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"); });

查看更多
登录 后发表回答