Page 1 of 1

[SOLVED] Best way to validate SSN

Posted: Wed Jul 11, 2018 4:52 pm
by karmacomposer
What would be a good way to have a user enter a social security number and automatically put the '-' in while they input.

So, they type 123456789 and the result is 123-45-6789

Also, how do I then hide all but the last 4 digits with bullets or asteriks?

I already have numbers only code in place.

Mike

Re: Best way to validate SSN

Posted: Wed Jul 11, 2018 5:31 pm
by dunbarx
So much fun.

Make a new field. Put this in its script:

Code: Select all

on keyDown tKey
   if tKey is an integer and the length of me < 11 then put tKey after me
   if the length of me < 8 and the last char of me is an integer then  set the imageSource of the last char of me to arrow
   if the length of me = 3 or the length of me = 6 then put "-" after me
end keyDown
A couple of things. I just threw this together, so technically the actual digit will appear in the field before the imageSource is set. You cannot see it because computers are fast.

Also, I would change the imageSource to something more ordinary, like a bullet point. I just used "arrow" because I am lazy.

There are certainly issues. For example, if you backspace in the middle of the first group to delete a digit, or if you delete one of those dashes, you will not be happy with the result. I would be interested to hear how you manage that.

Watch it, Lagi. :shock: You too, Jacque. :wink:

Craig Newman

Re: Best way to validate SSN

Posted: Wed Jul 11, 2018 8:43 pm
by dunbarx
It was either go back to work or play around...

Put this into the field script:

Code: Select all

on rawkeyDown tkey
   get the selectedChunk
   if the selectedtext contains "-" then exit to top
   
   if word 4 of it > word 2 of it then
      put word 2 of it into startChar
      put word 4 of it into endChar
   else
      put word 4 of it into startChar
      put word 4 of it into endChar
   end if
   
   switch
      case tKey =  65288 --backspace key
         delete char startChar to endChar of me
         break
      case the length of me = 11 --no more digits allowed
         exit to top
         break
      case  tKey > 47 and tkey < 58 --field open for entry
         put numToChar(tKey) after char startChar of me
         if  the length of me = 3 or the length of me = 6 then put "-" after me
         if startChar < 7 then set the imageSource of char startChar + 1 of me to bullet
   end switch
end rawkeyDown
"Bullet" has to be a resident image.

The use of "rawKeyDown" allows the inclusion of the backspace key. All that startChar and endChar nonsense is to allow the user to select a block of digits. But it will not allow the deletion of a string that contains a "-".

Rats. Back to work.

Craig

Re: Best way to validate SSN

Posted: Wed Jul 11, 2018 9:46 pm
by FourthWorld
The safest thing to do with information as critical as SSN is to never require it. I'm sure you've exhausted all alternatives before committing to something that will make your system a target, but this is important enough to include in this discussion for the benefit of future readers.

Re: Best way to validate SSN

Posted: Thu Jul 12, 2018 3:43 am
by karmacomposer
Thank you guys.

Dunbarx, this is perfect - way above and beyond the call of duty - thank you very much for making my life a bit easier.

This is a form for a client - they require the SSN. Reading the data back will put asteriks in all but the last four digits, as expected and all data is encrypted.

Mike