Gossamer Forum
Home : Products : DBMan : Discussions :

validating range for numeric field

Quote Reply
validating range for numeric field
Is there a way to validate that a numeric value is within a certain range?
I want to enter an hour into a field so it needs to be between 0 and 24.

Can this be done with regular expression or needs to be done by modifying the code?
Thanks franK
Quote Reply
Re: [klatilf] validating range for numeric field In reply to
Quick & Dirty Solutions:


1. Dbman solution in default.cfg use [0-24] as valid_expr:
Code:
%db_def = (
ID => [0, 'numer', 5, 8, 1, '', ''],
HOURS => [8, 'alpha', 0, 3, 0, '', '[0-24]'],
Userid => [9, 'alpha', -2, 15, 0, '', '']
);


2. JavaScript Solution in html.pl:
Code:
<SCRIPT LANGUAGE="JavaScript">
function checkHours() {
if (form.HOURS.value > 24) {alert('Enter a Valid Hour')}
}
</SCRIPT>


<INPUT TYPE="text" NAME="HOURS" VALUE="$rec{'HOURS'}" SIZE="02" MAXLENGTH="02" onChange="checkHours();">


3. HTML Solution in html.pl:
Code:
<SELECT NAME="HOURS">
<OPTION VALUE="01">01</OPTION>
...options 2-23 go here...
<OPTION VALUE="24">24</OPTION>
</SELECT>