Back to feed
Renewal·서른의 생활코딩

Sample Source 4) JavaScript Basic Document Structure (String Object 2 — Example 1)

NS
normalstory
cover image
 Sample Source 4) JavaScript Basic Document Structure (String Object 2 — Example 1)


Creating a Resident Registration Number Validation Example

First, we need to know the rules of resident registration numbers...
첫번째로 860624-1080421" 라면 2,3,4,5,6,7,8,9,2,3,4,5 순으로 곱해야하고 11로 나누고 and the result subtracted again from 11 should equal the final digit

..so they say.



Honestly, I didn't fully understand it at first either.
First, by seeing the code run through examples, you can roughly it makes sense. 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
<title> </title>
<meta name="Keywords" content="" />
<meta name="Description" content="" />
<script type="text/javascript">
//<![CDATA[
var idNum="860624-1080421"
var value=2; // because we start multiplying from 2, the initial value is 2.
var gap1=0;
var total;
for(i=0; i < idNum.length-1; i++){
if(i==6) continue; // to skip the pairs
if(value>9){ // because we multiply in the order 2,3,4,5,6,7,8,9,2,3,4,5
value=2;
}
gap1=gap1+idNum.charAt(i)*value; // charAt(i) => returns the i-th value from the index.
value++;
}
total=11-(gap1%11);
if(total>9){
total%=10; // take only the ones digit == by dividing by 10
}
alert(total);
// Bonus: first, get the resident registration number from the user.
//]]]]>
</script>
</head>
<body>
</body>
</html>

This English version was translated by Claude.

친절한 찰쓰씨
Written by
친절한 찰쓰씨

Pleasant Charles — UI/UX researcher at AIT. Keeping notes on design, planning, and slow days here since 2010.

More on the author's page

Keep reading

Renewal

Steadily, for the long haul, without burning out

Mar 31, 2026·9 min
Renewal

Tech-life balance

Feb 7, 2026·3 min
Renewal

Humanality, by Park Jeong-ryeol

Feb 7, 2026·11 min