473,327 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Regular Expression for signed floating point number not working

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> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;
</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]
Dec 24 '07 #1
3 2988
gits
5,390 Expert Mod 4TB
hi ...

instead of using a regExp you could use a function like the following:

Expand|Select|Wrap|Line Numbers
  1. function test_value(val) {
  2.     return (!isNaN(val) && (val >= -10 && val <= 10));
  3. }
  4.  
kind regards
Dec 24 '07 #2
hi ...

instead of using a regExp you could use a function like the following:

Expand|Select|Wrap|Line Numbers
  1. function test_value(val) {
  2.     return (!isNaN(val) && (val >= -10 && val <= 10));
  3. }
  4.  
kind regards
Thanks gits,
It's working fine now...
Dec 27 '07 #3
gits
5,390 Expert Mod 4TB
glad to hear that :) ... post back to the forum anytime you have more questions ...

kind regards
Dec 27 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
10
by: Jeff Sandler | last post by:
I have a page that accepts input from many textboxes. Many of the textboxes are intended to accept dates and times, thus, I expect only digits to be entered. I originally tested using parseInt...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
11
by: Michael_Burgess | last post by:
Hi there, I'm using the following regex validator: ^\d{0,4}.?\d{0,2}$ This is to validate that a text box has 0-4 numbers, possible followed by a decimal point and possibly followed by 2...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.