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
[SOLVED] Best way to validate SSN
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 361
- Joined: Wed Apr 27, 2011 2:12 pm
[SOLVED] Best way to validate SSN
Last edited by karmacomposer on Thu Jul 12, 2018 3:47 am, edited 1 time in total.
-
- VIP Livecode Opensource Backer
- Posts: 9587
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Best way to validate SSN
So much fun.
Make a new field. Put this in its script:
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. You too, Jacque.
Craig Newman
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
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. You too, Jacque.
Craig Newman
-
- VIP Livecode Opensource Backer
- Posts: 9587
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Best way to validate SSN
It was either go back to work or play around...
Put this into the field script:
"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
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
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
-
- VIP Livecode Opensource Backer
- Posts: 9804
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Best way to validate SSN
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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- Posts: 361
- Joined: Wed Apr 27, 2011 2:12 pm
Re: Best way to validate SSN
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
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