Zend Framework Forum

Go Back   Zend Framework Forum > Zend Framework Components > Core Infrastructure

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-05-2008, 06:01 PM
Junior Member
 
Join Date: Jul 2008
Posts: 6
Default How do I validate a URL?

I'm using Zend_Filter_Input to validate some input, and one of the textboxes allows you to enter a URL in. I need to validate the URL to make sure it is in the proper Website.com format. In fact, it's supposed to point to an image, so I'm hoping I can override the validator (if one already exists) so it checks for a proper image url.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-06-2008, 06:29 AM
Junior Member
 
Join Date: Mar 2008
Posts: 17
Default

And what is proper image url?
image34534534534534
image.php?gen=23423423423
/image/7234273642734
image.jpg -> rewrite hack.pl
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-11-2008, 04:16 PM
Junior Member
 
Join Date: Jul 2008
Posts: 6
Default

I figured it out, thanks anyway.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 10-28-2008, 12:54 PM
Member
 
Join Date: Jul 2008
Location: london
Posts: 34
Default how?

Hi Bulletproof

I'm also trying to validate a URL. How did you do it?

I need to validate URLs like:
Code:
http://www.websites.com
http://subdomain.websites.com
http://www.websites.com/directory/
http://www.websites.com/index.php?whatever=xyz
I've tried using Hostname, but it fails on any URLs with a directory.

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-10-2009, 12:06 AM
Junior Member
 
Join Date: Feb 2009
Posts: 1
Default Extend Zend_Validate_Abstract

You can validate a URI using Zend_Uri but it doesn't implement the Zend_Validate_Interface. So, you'll have to roll your own. Fortunately, it's pretty easy to do so:

[PHP]
class Url_Validator extends Zend_Validate_Abstract
{
const INVALID_URL = 'invalidUrl';

protected $_messageTemplates = array(
self::INVALID_URL => "'%value%' is not a valid URL.",
);

public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);

if (!Zend_Uri::check($value)) {
$this->_error(self::INVALID_URL);
return false;
}
return true;
}
}

// When creating the form:
$website = $form->createElement('text', 'website');
$website->addValidator(new Url_Validator);
[/PHP]

Hope that helps
-steve
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 03-27-2009, 06:41 PM
Rhino's Avatar
Senior Member
 
Join Date: Feb 2009
Location: Lost Angeles, CA
Posts: 105
Send a message via AIM to Rhino
Default

nice! that works pretty well. thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 05-21-2009, 04:32 AM
Junior Member
 
Join Date: May 2009
Posts: 4
Default

How about just passing a REGEX to the validator as an alternative:
Zend Framework: Documentation
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT. The time now is 12:05 AM.


Designed by: Miner Skinz Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0