Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Check VALID Identity Card JavaScript to J2SE Code

807605Aug 12 2007 — edited Aug 12 2007
I want to implements a check identity card code
but the sample i got is in javascript format.

anyone can help me change the code to J2SE workable java code

Thanks

S -7 NUMBERS - LETTER

example:

Identity Card in my Country is : S1234567D
function IsValidNRIC( szFieldName )
{
var sNRIC = TrimString(szFieldName.value);
var NRIC;
NRIC = sNRIC.toUpperCase();
var number;
var sum = 0;
var p;
//ChinKiat 30092003, Validation for NRIC first character
if( NRIC.charAt(0) != "S" && NRIC.charAt(0) != "T")
{
return false;
}
//end
if( NRIC.length != 9 ) {
return false;
}
number = NRIC.substring( 1, 8 );
if( isNaN( number ) ) {
return false;
}
sum += parseInt( number.charAt( 0 ) ) * 2;
sum += parseInt( number.charAt( 1 ) ) * 7;
sum += parseInt( number.charAt( 2 ) ) * 6;
sum += parseInt( number.charAt( 3 ) ) * 5;
sum += parseInt( number.charAt( 4 ) ) * 4;
sum += parseInt( number.charAt( 5 ) ) * 3;
sum += parseInt( number.charAt( 6 ) ) * 2;
if( NRIC.charAt( 0 ) == 'T' ) {
sum += 4;
}

p = 11 - ( sum % 11 );
if( p == 1 && NRIC.charAt( 8 ) == 'A' ) {
return true;
}
if( p == 2 && NRIC.charAt( 8 ) == 'B' ) {
return true;
}
if( p == 3 && NRIC.charAt( 8 ) == 'C' ) {
return true;
}
if( p == 4 && NRIC.charAt( 8 ) == 'D' ) {
return true;
}
if( p == 5 && NRIC.charAt( 8 ) == 'E' ) {
return true;
}
if( p == 6 && NRIC.charAt( 8 ) == 'F' ) {
return true;
}
if( p == 7 && NRIC.charAt( 8 ) == 'G' ) {
return true;
}
if( p == 8 && NRIC.charAt( 8 ) == 'H' ) {
return true;
}
if( p == 9 && NRIC.charAt( 8 ) == 'I' ) {
return true;
}
if( p == 10 && NRIC.charAt( 8 ) == 'Z' ) {
return true;
}
if( p == 11 && NRIC.charAt( 8 ) == 'J' ) {
return true;
}
return false;
}
Message was edited by:
baoky
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 9 2007
Added on Aug 12 2007
15 comments
512 views