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

Sample Source 3) JavaScript Basic Document Structure (String Object — Application 1)

NS
normalstory
cover image

This time, let's briefly test a resident registration number validation program — something commonly seen around us.

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8" />

<title></title>

<script type="text/javascript">

//<![CDATA[


var ssn="123456-123-456";


var check2=ssn.indexOf("-");  // from the left

var check3=ssn.lastIndexOf("-"); // from the right


document.write(check2 + "<br />");

document.write(check3 + "<br />");


//if((check2!/* position of '-'..*/=6)||(ssn.length!/* total length..*/=14)||(check2!=check3/* there must be only one '-'..*/))
 

if((check2!=6)||(ssn.length!=14)||(check2!=check3))

{

alert("Invalid resident registration number.");

}


//]]>

</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.