jquerymaskedinput

jQuery's maskedinput with negative integer


How I can allow negative numbers in my mask using jQuery Masked Input plugin?


Solution

  • Start by going to the "documentation" page for the plugin. http://digitalbush.com/projects/masked-input-plugin/

    Then reference the section that starts with "You can now supply your own mask definitions."

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

    So you would probably want something like....

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

    I'm assuming the question mark at the end '[+-]?' will work as expected for a regex fragment.