Restricting Numeric Key to ten digits

I tried in limiting my digits to ten by using keypress instead - it looks promising at first as I am making it work flawlessly... at first. I however hit a stumbling block when I reached digit seven. I checked my scripts and everything looks in order or similar as what I did for the first four digits. Am I wrong here or did I reached a limit of keypress in SL? Is there a better script out there?please help!

9 Replies
OWEN HOLT

I don't think it's your file. I just built the logic from scratch and as soon as you hit an 8 digit number, there appears to be a rounding error in StoryLine's math.  This appears to be a bug.
Using a JavaScript solution prolongs when the error occurs, however, at or around 17 or 18 digits, the same anomaly occurs even when using JavaScript.

OWEN HOLT

The work around would be to store this as a string in StoryLine, convert it to a number with JavaScript, perform your calculation with JavaScript, convert the result back to a string, and send the updated string back to your StoryLine variable.  The string will keep it's integrity no matter the length of the number.

 

Raul Ramiro
OWEN HOLT

The work around would be to store this as a string in StoryLine, convert it to a number with JavaScript, perform your calculation with JavaScript, convert the result back to a string, and send the updated string back to your StoryLine variable.  The string will keep it's integrity no matter the length of the number.

 

Can you give me guides on how to do this? Thanks in advance :) Don't know that much in javascript

OWEN HOLT

Do you need it in true "numeric" format with comma separators or is a long string of numbers acceptable?  

I ask because if you keep it numeric, you might run into problems with exceeding JavaScript's safe integer (read about it here).  You could still do it with text but it would involve constantly analyzing the string and breaking it into groups of 3 starting at the right end moving backwards and reassembling them with commas (or simply putting them in an array and converting it to a string).  Either way, it could end up being a lot of script to run on each keystroke.

Leaving out the commas is much cleaner and simpler from a coding perspective, but less attractive or familiar from a learner's.

Raul Ramiro
OWEN HOLT

Do you need it in true "numeric" format with comma separators or is a long string of numbers acceptable?  

I ask because if you keep it numeric, you might run into problems with exceeding JavaScript's safe integer (read about it here).  You could still do it with text but it would involve constantly analyzing the string and breaking it into groups of 3 starting at the right end moving backwards and reassembling them with commas (or simply putting them in an array and converting it to a string).  Either way, it could end up being a lot of script to run on each keystroke.

Leaving out the commas is much cleaner and simpler from a coding perspective, but less attractive or familiar from a learner's.

numeric keys but no comma needed.