2 b) Modify the 2 a) program to get the current semester also (restricted to be a number from 1 to 8)
<html >
<script type="text/javascript">
function chkusn()
{
var str=document.getElementById("usn");
var result=str.value.search(/^[1-4]{1}[A-Z]{2}\d{2}[A-Z]{2}\d{3}$/);
var stsem=document.getElementById("sem");
var pos=stsem.value.search(/^[1-8]{1}$/);
if(result >= 0 && pos >= 0)
{
alert("entered usn ("+str.value+") is in the correct form \n" +" entered sem("+stsem.value+")is in the correct form\n");
}
else if(result != 0 && pos>= 0)
{
alert ("entered usn("+str.value+") is not in correct form \n"+" the correct path is 1ST10IS039\n"+"please go back and re enter your USN");
}
else if(result >= 0 && pos != 0)
{
alert("entered sem("+stsem.value+")is not in the correct range \n" + "the range is between 1 to 8 \n");
}
else
{
alert ("entered usn("+str.value+") is not in correct form \n"+" the correct path is 1ST10IS039\n"+"entered sem("+stsem.value+")is not in the correct range \n" + "the range is between 1 to 8 \n " + "please go back and re enter your USN,SEM");
}
}
</script>
</head>
<center>
<form name="my form">
<p style="color:red;font-size:28px"> <bold>ENTER YOUR USN</bold> </p>
<input type="text" id="usn" size=28 />
<br/><p style="color:red;font-size:28px"> <bold>ENTER YOUR SEM</bold> </p>
<input type="text" id="sem" size=28 />
<br><br><br>
<input type="button" onclick="chkusn()" value="validate"/>
<input type="reset" value="reset" />
<br/>
</form>
</center>
</html>
<html >
<script type="text/javascript">
function chkusn()
{
var str=document.getElementById("usn");
var result=str.value.search(/^[1-4]{1}[A-Z]{2}\d{2}[A-Z]{2}\d{3}$/);
var stsem=document.getElementById("sem");
var pos=stsem.value.search(/^[1-8]{1}$/);
if(result >= 0 && pos >= 0)
{
alert("entered usn ("+str.value+") is in the correct form \n" +" entered sem("+stsem.value+")is in the correct form\n");
}
else if(result != 0 && pos>= 0)
{
alert ("entered usn("+str.value+") is not in correct form \n"+" the correct path is 1ST10IS039\n"+"please go back and re enter your USN");
}
else if(result >= 0 && pos != 0)
{
alert("entered sem("+stsem.value+")is not in the correct range \n" + "the range is between 1 to 8 \n");
}
else
{
alert ("entered usn("+str.value+") is not in correct form \n"+" the correct path is 1ST10IS039\n"+"entered sem("+stsem.value+")is not in the correct range \n" + "the range is between 1 to 8 \n " + "please go back and re enter your USN,SEM");
}
}
</script>
</head>
<center>
<form name="my form">
<p style="color:red;font-size:28px"> <bold>ENTER YOUR USN</bold> </p>
<input type="text" id="usn" size=28 />
<br/><p style="color:red;font-size:28px"> <bold>ENTER YOUR SEM</bold> </p>
<input type="text" id="sem" size=28 />
<br><br><br>
<input type="button" onclick="chkusn()" value="validate"/>
<input type="reset" value="reset" />
<br/>
</form>
</center>
</html>
No comments:
Post a Comment