Answers.Body: <p>Craft extends Yii's <a href="http://www.yiiframework.com/doc/api/1.1/CUrlValidator" rel="nofollow">CUrlValidator</a> to <a href="https://experiencehq.net/blog/the-definitive-guide-to-validation-in-craft-part-2-attributetypes" rel="nofollow">add support</a> for protocol-less URLs as well as URLs without a TLD (such as your example of <code>http://sdfsdfsfsdfsdf</code>).</p>
  
  <p>If you need other behaviors for your URL validation, you can always write a <a href="https://experiencehq.net/blog/the-definitive-guide-to-validation-in-craft-part-5-custom-validators" rel="nofollow">custom URL validator</a>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-22T05:03:34.553Z
Answers.LastActivityDate: 2015-11-22T05:03:34.553Z
Answers.UserDisplayName: Brad Bell
Body: <p>I have a basic model defined:</p>
  
  <pre><code>protected function defineAttributes()
  {
      return array(
          'id'        =&gt; array(AttributeType::String, 'required' =&gt; true),
          'url'       =&gt; AttributeType::Url,
          'info'      =&gt; array(AttributeType::String, 'required' =&gt; true, 'maxLength' =&gt; 4000),
          'title'     =&gt; array(AttributeType::String, 'required' =&gt; true, 'maxLength' =&gt; 65, 'minLength' =&gt; 15),
          'message'   =&gt; AttributeType::String,
      );
  }
  </code></pre>
  
  <p>And when checking if the model is valid:</p>
  
  <pre><code>if (!$my_model-&gt;validate())
  {
      return false;
  }
  </code></pre>
  
  <p>Almost any string for 'url' is passing the validation, even without a '.com' </p>
  
  <p>So if someone inputs <strong>sdfsdfsfsdfsdf</strong> in the input field, it'll pass as a valid URL and return as <strong><a href="http://sdfsdfsfsdfsdf" rel="nofollow">http://sdfsdfsfsdfsdf</a></strong></p>
  
  <p>I've also tried using <strong>AttributeType::UrlFormat</strong> but I run into the same problem. Am I not understanding what this attributetype does, or should it be validating that it's an actual URL string?</p>
  
Tags: <plugin-development><form><models><attribute>
Title: Using $model->validate() with AttributeType::Url
ThreadText: # Using $model->validate() with AttributeType::Url
  
  (Asked by: username_0 on 2015-11-22)
  
  I have a basic model defined:
  
  ```
  protected function defineAttributes()
  {
      return array(
          'id'        => array(AttributeType::String, 'required' => true),
          'url'       => AttributeType::Url,
          'info'      => array(AttributeType::String, 'required' => true, 'maxLength' => 4000),
          'title'     => array(AttributeType::String, 'required' => true, 'maxLength' => 65, 'minLength' => 15),
          'message'   => AttributeType::String,
      );
  }
  
  ```
  
  And when checking if the model is valid:
  
  ```
  if (!$my_model->validate())
  {
      return false;
  }
  
  ```
  
  Almost any string for 'url' is passing the validation, even without a '.com'
  
  So if someone inputs **sdfsdfsfsdfsdf** in the input field, it'll pass as a valid URL and return as **<http://sdfsdfsfsdfsdf>**
  
  I've also tried using **AttributeType::UrlFormat** but I run into the same problem. Am I not understanding what this attributetype does, or should it be validating that it's an actual URL string?
  
  **Tags:** plugin-development, form, models, attribute
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-11-22. Score: 1 | Accepted answer
  
  Craft extends Yii's [CUrlValidator](http://www.yiiframework.com/doc/api/1.1/CUrlValidator) to [add support](https://experiencehq.net/blog/the-definitive-guide-to-validation-in-craft-part-2-attributetypes) for protocol-less URLs as well as URLs without a TLD (such as your example of `http://sdfsdfsfsdfsdf`).
  
  If you need other behaviors for your URL validation, you can always write a [custom URL validator](https://experiencehq.net/blog/the-definitive-guide-to-validation-in-craft-part-5-custom-validators).
  
  
  ---
  
  