Forums

Validating a Numeric Range: High and Low Limit

mruetz 22 Apr, 2009
I looked around the forum but couldn't find this answer but sure it has been solved before....

Is there any sample code to validate a numeric form value.

For instance, I want the user to type in a number in the form and make sure the value is between 1 and 50.

Any suggestions?
GreyHead 22 Apr, 2009
Hi mruetz,

Yes, I think I posted this yesterday (but my memory could be failing).

Bob
Max_admin 22 Apr, 2009
Yes, Bob posted this yesterday, please check for it.

Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
mruetz 22 Apr, 2009
I have been looking for it but haven't found it yet (using search and browsing as well). I will continue to look for it, but if anyone finds this thread, please post a link. Many thanks, Matt
GreyHead 22 Apr, 2009
Hi mruetz,

Well I can't find it either - I'll try again in the morning (or re-write it).

Bob
mruetz 23 Apr, 2009
Thanks Bob!
Max_admin 24 Apr, 2009
Try to make an advanced search and set the author to greyhead and look for his posts at 22,21,20 of this month ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 24 Apr, 2009
Hi mruetz,

Something like this added to your Form HTML (not the Javascript box)
<?php
$script = "
var field_id = new LiveValidation('field_id');
field_id.add( Validate.Length, { 
  minimum: 4, 
  maximum: 8 
});
";
$script = "
window.addEvent('domready', function() {
  $script
});
";
$doc =& JFactory::getDocument();
$doc->addScriptDeclaration($script);
?>

Note : only the two script lines var field_id . . . and field_id.add do the validation. the rest is to load it correctly into the page.

Replace 'field_id' three times with the id of the field you want to validate; and set the max & min parameters.

Bob
rhapsody 12 May, 2009
Hi Bob,

How can I ensure a minimum value of 10.00 in a field.

--- edited later:

Found it:
<?php
$script = "
var text_0 = new LiveValidation('text_0');
text_0.add( Validate.Numericality, { 
  minimum: 10
});
";
$script = "
window.addEvent('domready', function() {
  $script
});
";
$doc =& JFactory::getDocument();
$doc->addScriptDeclaration($script);
?>


Thanks!
This topic is locked and no more replies can be posted.