मुझे डर है कि आप अपने स्वयं के कस्टम सत्यापनकर्ता बनाने की आवश्यकता होगी हूँ:
class myCustomValidatorUrl extends sfValidatorRegex
{
const REGEX_URL_FORMAT = '~^
((%s)://)? # protocol
(
([a-z0-9-]+\.)+[a-z]{2,6} # a domain name
| # or
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} # a IP address
)
(:[0-9]+)? # a port (optional)
(/?|/\S+) # a /, nothing or a/with something
$~ix';
protected function configure($options = array(), $messages = array())
{
parent::configure($options, $messages);
$this->addOption('protocols', array('http', 'https', 'ftp', 'ftps'));
$this->setOption('pattern', new sfCallable(array($this, 'generateRegex')));
}
public function generateRegex()
{
return sprintf(self::REGEX_URL_FORMAT, implode('|', $this->getOption('protocols')));
}
}
यहाँ ((%s)://)?
का मतलब है कि अब प्रोटोकॉल वैकल्पिक है। एक मूल पैटर्न (REGEX_URL_FORMAT const) के लिए sfValidatorUrl देखें।
अपने उपयोगकर्ताओं को उचित यूआरएल दर्ज करने के लिए क्यों न पूछें? या अगर जावास्क्रिप्ट में प्रोटोकॉल नहीं है तो http: // को प्रीपेन्ट करने के लिए कुछ जावास्क्रिप्ट जोड़ें। तब वे यह भी जान लेंगे कि यह वहां है। – ThiefMaster
ThiefMaster, वहां बहुत सारे उपयोग मामले हैं जहां आप डेटाबेस में यूआरएल प्रोटोकॉल को हार्डकोड नहीं करना चाहते हैं। – Acyra