Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

How restrict Alphabets and Special characters in the numeric box and allow range only 0-999 in the numeric box.

How restrict Alphabets and Special characters in the numeric box and allow range only 0-999 in the numeric box.
asked Oct 9, 2015 by sandeepkapalawai Bronze (1,475 points)
You won't be using a numeric question for your problem.

You will need to use a single row O/E question and apply JavaScript to limit the character set to 0-999 and the special characters you desire.

1 Answer

0 votes
<script type="text/javascript">


$(".numeric_input").keydown(function(event) {
   
        //assign maximum value to be allowed to x i.e 100 or 999 or etc as per requirement
        var x=999;
       
        // Allow: backspace, delete, tab, escape, enter (. key code==190,110 required for decimal input, so append 190,110 in array for decimal input)}
        // Allow: Ctrl+A
        // Allow: home, end, left, right
        if ( $.inArray(event.keyCode,[46,8,9,27,13]) !== -1 || (event.keyCode == 65 && event.ctrlKey === true) || (event.keyCode >= 35 && event.keyCode <= 39))
        {
            // let it happen, don't do anything
            return;
           
        }
        else
        {
            // to allow range 0-x dynamically
            var q,r,kc;
            q=parseInt(x/10);
            r=""+(x%10);
            kc=r.charCodeAt(0);
       
            if($(this).val()>q || ($(this).val()==q && (event.keyCode < 48 || (event.keyCode > kc && event.keyCode <96) || event.keyCode > 96+(kc-48)))||($(this).val()!="" && $(this).val()==0 &&(event.keyCode == 48 || event.keyCode ==96)) )
            {
                event.preventDefault();
            }
           
            // Ensure that it is a number and stop the keypress
            if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 ))
            {
                event.preventDefault();
            }   
        }
    });
</script>



Please place this in footer
answered Feb 3, 2016 by KarthikMahankali Bronze (1,445 points)
...