![]() |
|
|||||||
| Chit Chat Public Talk about any thing you want! This forum is public. |
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||||||||||
|
||||||||||||
|
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 |
|
#2
|
|||||||||||
|
|||||||||||
|
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. |
|
#3
|
||||||||||||
|
||||||||||||
|
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? |
|
#4
|
|||||||||||
|
|||||||||||
|
Hi Scroller,
I had another look/see, and it's working now. |
|
#5
|
|||||||||||
|
|||||||||||
|
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.
|
|
#6
|
|||||||||||
|
|||||||||||
|
I've no idea..I'm just a pawn in this chess game.
|
|
#7
|
|||||||||||
|
|||||||||||
|
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 |
|
#8
|
||||||||||||
|
||||||||||||
|
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 ... |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| javascript arror now | generic | Chit Chat Public | 0 | 01-04-2005 12:27 PM |