Reseller Hosting, Shared Hosting, Dedicated Hosting by Vortech Inc.

Go Back   Reseller Hosting, Shared Hosting, Dedicated Hosting by Vortech Inc. > >> General Public > Chit Chat Public
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Chit Chat Public Talk about any thing you want! This forum is public.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 04-15-2003, 02:55 PM
Scroller's Avatar
Scroller Scroller is offline
Vortech Inc. Customer
Vortech Inc. Customer
 
Location: Singapore
Red face Javascript Experts Come In Please

I'm hoping to "translate" this function writtein in ASP into Javascript. Not much luck so far (Javascipt is virtually impossible to debug), can anyone give me a hint?


Private function chkNRIC(NRIC)
'checks for a vaild nric, returns 1 for invalid nric, returns 0 for valid nric
chkNRIC = 0

'weightage 2,7,6,5,4,3,2
Dim W_Array(8)
W_Array(1) = 2
W_Array(2) = 7
W_Array(3) = 6
W_Array(4) = 5
W_Array(5) = 4
W_Array(6) = 3
W_Array(7) = 2

'last character
'A B C D E F G H I Z J
Dim char_Array(11)
char_Array(1) = "A"
char_Array(2) = "B"
char_Array(3) = "C"
char_Array(4) = "D"
char_Array(5) = "E"
char_Array(6) = "F"
char_Array(7) = "G"
char_Array(8) = "H"
char_Array(9) = "I"
char_Array(10) = "Z"
char_Array(11) = "J"

'check length (9 is correct)
If Len(NRIC) <> 9 then
chkNRIC = 1

'check last character

else
DIM i, sum_n, key_digit, lastAlpha
sum_n = 0

For i = 2 to 8
if IsNumeric(mid(nric,i,1)) then
sum_n = sum_n + (CInt(mid(nric,i,1))) * (CInt(W_Array(i-1)))
end if
Next

key_digit = 11 - (sum_n mod 11)
lastAlpha = char_Array(key_digit)

if lastAlpha <> Right(NRIC,1) then
chkNRIC = 1
end if

End if

end function
Reply With Quote
  #2  
Old 04-16-2003, 01:11 PM
sequill sequill is offline
Vortech Inc. Customer
Vortech Inc. Customer
 
I put up a JavaScript version / demo at:
http://www.sequill.net/chkNRIC.html

I didn't have a valid nric value to check and I wasn't going to work one out...if it works,great... if it doesn't, give me some valid values so I can test it.
Reply With Quote
  #3  
Old 04-16-2003, 01:25 PM
Scroller's Avatar
Scroller Scroller is offline
Vortech Inc. Customer
Vortech Inc. Customer
 
Location: Singapore
hi sequil

thanks a million for the help

I tested, something seems to be wrong still cos valid ones can't get pass ...

these are a couple of valid ones that I have ...
8433044B
7620977D
8113766H
8329110I

any idea?
Reply With Quote
  #4  
Old 04-16-2003, 11:41 PM
sequill sequill is offline
Vortech Inc. Customer
Vortech Inc. Customer
 
Hi Scroller,
I had another look/see, and it's working now.
Reply With Quote
  #5  
Old 04-16-2003, 11:45 PM
landiserve
Guest
 
Pardon my ignorance, but what is NRIC? I even looked it up and couldn't find much about it, except some organization that use those initials, and one discussion on DevShed about it, but with few details about what it was.
Reply With Quote
  #6  
Old 04-16-2003, 11:49 PM
sequill sequill is offline
Vortech Inc. Customer
Vortech Inc. Customer
 
I've no idea..I'm just a pawn in this chess game.
Reply With Quote
  #7  
Old 04-17-2003, 12:02 AM
vonbrocklin vonbrocklin is offline
Defensive Tackle
Vortech Inc. Customer
 
You got me curious so I searched too - it is a Singapore Identity Card Number...
__________________
"If everything is under control, you're going too slow." -- Mario Andretti
Reply With Quote
  #8  
Old 04-17-2003, 02:20 AM
Scroller's Avatar
Scroller Scroller is offline
Vortech Inc. Customer
Vortech Inc. Customer
 
Location: Singapore
hi sequill,

thank you very much. it's working beautifully it all appears so clear now (esp. after spending hours going in circles).

anyway, yap! that's the identification number over here in Singapore. We very much ran out of numbers so the government actually started a new algorithm for newborns in the last 1-2 years. still trying to figure that out. arrgghhh ...
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript arror now generic Chit Chat Public 0 01-04-2005 12:27 PM


All times are GMT -5. The time now is 05:00 AM.


Powered by vBulletin Version 3.5.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Vortech Inc. ©2005
Page generated in 0.37743 seconds with 16 queries
[Output: 67.95 Kb. compressed to 62.69 Kb. by saving 5.26 Kb. (7.74%)]