Hi,
I donot have much knowledge of R.Exp. In my web page I am required to validate numeric textboxes allowing signed/unsigned integer/float numbers and then compare between them. I need the textboxes to accept values only between -10 to +10. Please help? Below is my code
[PHP]
<html>
<head>
<title>
Display Requirements
</title>
<script language = "javascript">
var numericExpression = /^(((-|\+)?\d+(\.\d*)?)|((-|\+)?(\d*\.)?\d+))$/ ; // this exp should accept both signed/unsigned integer/float numbers
for(var i = 1; i <= 5; i++)
{
//alert("in for");
var FL_id = 'FL' + i;
var TL_id = 'TL' + i;
var FH_id = 'FH' + i;
var TH_id = 'TH' + i;
var FL_value = document.getElementById(FL_id).value;
var TL_value = document.getElementById(TL_id).value;
var FH_value = document.getElementById(FH_id).value;
var TH_value = document.getElementById(TH_id).value;
// ---------- From LOW validation(can't be blank or non-numeric) -----------
if(FL_value == "" || FL_value == null)
{
alert("The Ranges cannot be left blank") ;
document.getElementById(FL_id).style.background = 'Yellow';
document.getElementById(FL_id).focus();
return false;
}//if(FL_value == "" || FL_value == null) over
else
{
var float_FL_value = parseFloat(FL_value) ;
//alert("float_FL_value: " + float_FL_value);
if(FL_value.match(numericExpression))
{
document.getElementById(FL_id).style.background = 'White';
}// if(FL_value.match(numericExpression)) over
else
{
alert("The Ranges can only be numeric");
document.getElementById(FL_id).style.background = 'Yellow';
document.getElementById(FL_id).value = "" ;
document.getElementById(FL_id).focus() ;
return false;
}// else(FL_value.match(numericExpression)) over
}// else (FL_value.match(numericExpression)) over
// ---------- To LOW validation(can't be blank or non-numeric) -----------
if(TL_value == "" || TL_value == null)
{
alert("The ranges cannot be left blank") ;
document.getElementById(TL_id).style.background = 'Yellow';
document.getElementById(TL_id).focus();
return false;
}//if(TL_value == "" || TL_value == null) over
else
{
var float_TL_value = parseFloat(TL_value);
//alert("float_TL_value: " + float_TL_value);
if(TL_value.match(numericExpression))
{
document.getElementById(TL_id).style.background = 'White';
}// if(TL_value.match(numericExpression)) over
else
{
alert("The Ranges can only be numeric");
document.getElementById(TL_id).style.background = 'Yellow';
document.getElementById(TL_id).value = "" ;
document.getElementById(TL_id).focus() ;
return false;
}// else(TL_value.match(numericExpression)) over
}// else (TL_value.match(numericExpression)) over
// ---------- From HIGH validation(can't be blank or non-numeric) -----------
if(FH_value == "" || FH_value == null)
{
alert("The ranges cannot be left blank") ;
document.getElementById(FH_id).style.background = 'Yellow';
document.getElementById(FH_id).focus();
return false;
}//if(FH_value == "" || FH_value == null) over
else
{
var float_FH_value = parseFloat(FH_value);
if(FH_value.match(numericExpression))
{
document.getElementById(FH_id).style.background = 'White';
}// if(FH_value.match(numericExpression)) over
else
{
alert("The Ranges can only be numeric");
document.getElementById(FH_id).style.background = 'Yellow';
document.getElementById(FH_id).value = "" ;
document.getElementById(FH_id).focus() ;
return false;
}// else(FH_value.match(numericExpression)) over
}// else (FH_value.match(numericExpression)) over
// ---------- To HIGH validation(can't be blank or non-numeric) -----------
if(TH_value == "" || TH_value == null)
{
alert("The ranges cannot be left blank") ;
document.getElementById(TH_id).style.background = 'Yellow';
document.getElementById(TH_id).focus();
return false;
}//if(TH_value == "" || TH_value == null) over
else
{
var float_TH_value = parseFloat(TH_value);
if(TH_value.match(numericExpression))
{
document.getElementById(TH_id).style.background = 'White';
}// if(TH_value.match(numericExpression)) over
else
{
alert("The Ranges can only be numeric");
document.getElementById(TH_id).style.background = 'Yellow';
document.getElementById(TH_id).value = "" ;
document.getElementById(TH_id).focus() ;
return false;
}// else(TH_value.match(numericExpression)) over
}// else (TH_value.match(numericExpression)) over
// Validation for checking that To-Low is greater than From-Low; From-High is greater than To-Low; To-High is greater than From-High
//alert("here");
if(!(float_TL_value > float_FL_value))// means if to-low's value is NOT greater than from-low's value, then error-alert
{
alert("TO-LOW has to be greater than FROM-LOW");
document.getElementById(TL_id).style.background = 'Yellow';
document.getElementById(TL_id).focus();
return false;
}
if(!(float_FH_value > float_TL_value))// means if from-high's value is NOT greater than to-low's value, then error-alert
{
alert("FROM-HIGH has to be greater than TO-LOW");
document.getElementById(FH_id).style.background = 'Yellow';
document.getElementById(FH_id).focus();
return false;
}
if(!(float_TH_value > float_FH_value))// means if to-high's value is NOT greater than from-high's value, then error-alert
{
alert("TO-HIGH has to be greater than FROM-HIGH");
document.getElementById(TH_id).style.background = 'Yellow';
document.getElementById(TH_id).focus();
return false;
}
} //for(var i = 1; i <= 5; i++) over
return true;
}// checkForm() over
</script>
</HEAD>
<BODY onLoad = "bodyLoad()">
<form name = "DispForm" method = "get" action = "InsertJobRepMaster.php" onsubmit = "return checkForm()">
<fieldset>
<legend align = "center">
<b><font color = "blue">Display Requirements </font></b>
</legend>
<b>Company Name: <?php echo '<font color = "red">' . $_SESSION['companyname'] . '</font>' ;?></b><br>
<b>Job Name: <?php echo '<font color = "red">' . $_SESSION['jobname'] . '</font>' ;?></b><br>
<p align ="right">
<b>Welcome: <?php echo '<font color = "red">' . $_SESSION['username'] . '</font>' ; ?> </b> &n bsp; &nbs p; &n bsp;
</p>
<br>
<br>
<br>
<table id = "T1" align = "center" border = "1" cellpadding = "3" cellspacing = "0" style = "border-collapse: collapse" bordercolor = "#COCOCO">
<tr bgcolor = "pink">
<td>Sr. No</td>
<td>Qualities </td>
<td colspan = "2" align = "center">Low </td>
<td colspan = "2" align = "center">High </td>
</tr>
<tr>
<td></td>
<td></td>
<td>From </td>
<td>To </td>
<td>From </td>
<td>To </td>
</tr>
<tr>
<td bgcolor = "orange">1. </td>
<td>Exact Job-Individual Match </td>
<td><input tabindex = "1" type = "text" size = "5" id = "FL1" name = "FL1"></td>
<td><input tabindex = "2" type = "text" size = "5" id = "TL1" name = "TL1"></td>
<td><input tabindex = "3" type = "text" size = "5" id = "FH1" name = "FH1"></td>
<td><input tabindex = "4" type = "text" size = "5" id = "TH1" name = "TH1"></td>
</tr>
<tr>
<td bgcolor = "orange">2. </td>
<td>Good Compatibility to Job Requirement </td>
<td><input tabindex = "5" type = "text" size = "5" id = "FL2" name = "FL2"></td>
<td><input tabindex = "6" type = "text" size = "5" id = "TL2" name = "TL2"></td>
<td><input tabindex = "7" type = "text" size = "5" id = "FH2" name = "FH2"></td>
<td><input tabindex = "8" type = "text" size = "5" id = "TH2" name = "TH2"></td>
</tr>
<tr>
<td bgcolor = "orange">3. </td>
<td>Fair Compatibility to Job Requirement </td>
<td><input tabindex = "9" type = "text" size = "5" id = "FL3" name = "FL3"></td>
<td><input tabindex = "10" type = "text" size = "5" id = "TL3" name = "TL3"></td>
<td><input tabindex = "11" type = "text" size = "5" id = "FH3" name = "FH3"></td>
<td><input tabindex = "12" type = "text" size = "5" id = "TH3" name = "TH3"></td>
</tr>
<tr>
<td bgcolor = "orange">4. </td>
<td>Poor Compatibility to Job Requirement </td>
<td><input tabindex = "13" type = "text" size = "5" id = "FL4" name = "FL4"></td>
<td><input tabindex = "14" type = "text" size = "5" id = "TL4" name = "TL4"></td>
<td><input tabindex = "15" type = "text" size = "5" id = "FH4" name = "FH4"></td>
<td><input tabindex = "16" type = "text" size = "5" id = "TH4" name = "TH4"></td>
</tr>
<tr>
<td bgcolor = "orange">5. </td>
<td>Over-Focused Compatibility to Job Requirement </td>
<td><input tabindex = "17" type = "text" size = "5" id = "FL5" name = "FL5"></td>
<td><input tabindex = "18" type = "text" size = "5" id = "TL5" name = "TL5"></td>
<td><input tabindex = "19" type = "text" size = "5" id = "FH5" name = "FH5"></td>
<td><input tabindex = "20" type = "text" size = "5" id = "TH5" name = "TH5"></td>
</tr>
<tr>
<td colspan = "2" align = "center" ><input tabindex = "21" type = "submit" name= "ok" value = " OK "></td>
<td colspan = "4" align = "center" ><input tabindex = "22" type = "button" name = "cancel" value = " Cancel "> </td>
</tr>
</table>
</head>
</form>
</body>
</html>
[/PHP]