While working on a javascript issue for our project, we notice the strange behavior of integers and strings.We were about to validate the users Social Security Number and later we noticed if any customer types 001234567, it seems to be changed to a random number 342391.
Hardly its tough for us to save it in database.While debugging via firebug, we noticed during the client side validation , the numbers are changing. Lets try something like alert(000123456) in the javascript console, we will find a random number.
Then we came to conclusion, before passing the numbers for client side validation, we are converting it into string.So that random number won't get generated. So while dealing with the sensitive data like SSN number, please be aware to implement the number as strings instead integers.
Subscribe to:
Post Comments
(
Atom
)
001234567 is in javascript not treated as a base-10 number (Since it isn't! Numbers can't have prefix-0's). Instead it treats it as a number in octal form (http://www.diveintojavascript.com/core-javascript-reference/the-number-object)
ReplyDeleteThus 01234 in base 8 is actually 668 in base 10 (Decimal form).
If you need to represent a "number" with prefix-zeroes, it is by definition not a number, but a string. So you won't even be needing to convert it, simply pass it as the string it already is.