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>
