Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started