Html form in javascript

I want to make a CNP validator ( Romanian identity card - Wikipedia) in javascript through a form that has a button and a text input, but I don’t know how to make the html part, i only managed the java code.

function validCNP( p_cnp ) {

var i=0 , year=0 , hashResult=0 , cnp=[] , hashTable=[2,7,9,1,4,6,3,5,8,2,7,9];

if( p_cnp.length !== 13 ) { return false; }

for( i=0 ; i<13 ; i++ ) {

cnp = parseInt( p_cnp.charAt(i) , 10 );

if( isNaN( cnp ) ) { return false; }

if( i < 12 ) { hashResult = hashResult + ( cnp * hashTable ); }

}

hashResult = hashResult % 11;

if( hashResult === 10 ) { hashResult = 1; }

year = (cnp[1]*10)+cnp[2];

switch( cnp[0] ) {

case 1 : case 2 : { year += 1900; } break;

case 3 : case 4 : { year += 1800; } break;

case 5 : case 6 : { year += 2000; } break;

case 7 : case 8 : case 9 : { year += 2000; if( year > ( parseInt( new Date().getYear() , 10 ) - 14 ) ) { year -= 100; } } break;

default : { return false; }

}

if( year < 1800 || year > 2099 ) { return false; }

return ( cnp[12] === hashResult );

console.log(validCNP(numar));

}

If anyone can help me with the html form, i would appreciate it

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.