Question: hellow , How to write code html ,css and javascript for valdation id number by this code: Note: I need two fields of the same
hellow , How to write code html ,css and javascript for valdation id number by this code:
Note: I need two fields of the same type. Also, how do I make the verification result appear as text below the field and not in the alert()?
/////////////
/**
* @return {number}
*/
function validateSAID(id) {
id = id.trim();
if (isNaN(parseInt(id))) {
return -1;
}
if (id.length !== 10) {
return -1;
}
const type = id.substr(0, 1);
if (type !== '2' && type !== '1') {
return -1;
}
var sum = 0;
for (var i = 0; i < 10; i++) {
if (i % 2 === 0) {
const ZFOdd = String('00' + String(Number(id.substr(i, 1)) * 2)).slice(-2);
sum += Number(ZFOdd.substr(0, 1)) + Number(ZFOdd.substr(1, 1));
} else {
sum += Number(id.substr(i, 1));
}
}
return (sum % 10 !== 0) ? -1 : type;
}
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
