Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formvalidator Class for dates. Can't get it to work.

Status
Not open for further replies.

rogerzebra

Technical User
May 19, 2004
216
SE
hi,
I'm using formvalidation classes as validation, an execellent script I found somewere. Now I'm trying to add a date class and a class for street adresses, which I obviously can't get to work and could need someone to help out.
I have a form containing datefields( a javascript calender)on it and even that the fields has date information on them when executing the form, I get an error which indicate that both datefields are empty.

So now I'm not sure if my added regex classes for dates and streetaddress is correct? Once again if anyone could take time to look at them would be much appreciated.

This is the class script
Code:
class FormValidator
	{
	var $_errorList;
	function _getValue($field)
		
		{
		global ${$field};
		return ${$field};
		}

		function FormValidator()

		{
		$this->resetErrorList();
		}

//This is the classes I added

function isDatefield($field, $msg)
	
	{
		$value = $this->_getValue($field);
		$pattern = "/^([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})$/";	
		
		if(preg_match($pattern, $value))
		{
			return true;
		}
		else
		{
			$this->_errorList[] = array("field" => $field, "value" => $value, "msg" => $msg);
			return false;
		}
	}

function isStreetAddress($field, $msg)
	
	{
		$value = $this->_getValue($field);
		$pattern = "/^[0-9]+[a-zA-Z]+[a-zA-Z,]+[a-zA-Z]+[\d{5}]$/";
		if(preg_match($pattern, $value))
		{
			return true;
		}
		else
		{
			$this->_errorList[] = array("field" => $field, "value" => $value, "msg" => $msg);
			return false;
		}
	}
Thanks in advance
/rz
 
Wow, did you read my post???

I have a form containing datefields (a javascript calender)on it and even that the fields has date information on them when executing the form, I get an error which indicate that both datefields are empty.
So, now I'm not sure if my added regex classes for dates and streetaddress are correct?

Code:
function isDatefield($field, $msg)
    
    {
        $value = $this->_getValue($field);
        $pattern = "/^([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})$/";    
        
        if(preg_match($pattern, $value))
        {
            return true;
        }
        else
        {
            $this->_errorList[] = array("field" => $field, "value" => $value, "msg" => $msg);
            return false;
        }
    }


function isStreetAddress($field, $msg)
    
    {
        $value = $this->_getValue($field);
        $pattern = "/^[0-9]+[a-zA-Z]+[a-zA-Z,]+[a-zA-Z]+[\d{5}]$/";
        if(preg_match($pattern, $value))
        {
            return true;
        }
        else
        {
            $this->_errorList[] = array("field" => $field, "value" => $value, "msg" => $msg);
            return false;
        }
    }

I can't be more clear than that.../rz
 
hi,
the only error it generates is from the variable $fv's errorslist in php.

Code:
[i]$fv->isStreetAddress("Address", "Please enter an address");[/i]
[i]$fv->isDatefield("EffectiveDate", "Please pick a date in the effective date field");[/i]
if ($fv->isError())
{
	$errors = $fv->getErrorList();
	
	echo "<b>The operation could not be performed because one or more error(s) occurred.</b> <p> Please resubmit the form after making the following changes:";
	echo "<ul>";
	foreach ($errors as $e)
	{
		echo "<li>" . $e['msg'];
	}   
	echo "</ul>";
}
else
{
...
That's it, but what about the regular expressions are they okay as they are?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top