<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:www.refactormycode.com,2007:users125</id>
  <link type="application/atom+xml" href="http://www.refactormycode.com/users/125" rel="self"/>
  <title>Ali Karbassi</title>
  <updated>Sat Oct 13 19:08:14 -0700 2007</updated>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor417</id>
    <published>2007-10-13T19:08:14-07:00</published>
    <title>[JavaScript] On Is this year a leap year?</title>
    <content type="html">&lt;p&gt;Owen:&lt;/p&gt;

&lt;p&gt;According the Wikipedia, it's not JUST every 4 years.&lt;/p&gt;

&lt;p&gt;if year modulo 400 is 0 then leap
&lt;br /&gt;else if year modulo 100 is 0 then no_leap
&lt;br /&gt;else if year modulo 4 is 0 then leap
&lt;br /&gt;else no_leap&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Ali Karbassi</name>
      <email>ali.karbassi@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/14-is-this-year-a-leap-year/refactors/417" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code69</id>
    <published>2007-10-08T22:41:56-07:00</published>
    <updated>2010-10-22T22:48:28-07:00</updated>
    <title>[JavaScript] ucfirst</title>
    <content type="html">&lt;p&gt;I'm wondering if this could be made better.&lt;/p&gt;

&lt;pre&gt;String.prototype.ucfirst = function()
{
   // Split the string into words if string contains multiple words.
   var x = this.split(/\s+/g);
   for(var i = 0; i &amp;lt; x.length; i++)
   {
      // Splits the word into two parts. One part being the first letter,
      // second being the rest of the word.
      var parts = x[i].match(/(\w)(\w*)/);

      // Put it back together but uppercase the first letter and lowercase the rest of thw word.
      x[i] = parts[1].toUpperCase() + parts[2].toLowerCase();
   }

   // Rejoin the string and return.
   return x.join(' ');
};&lt;/pre&gt;</content>
    <author>
      <name>Ali Karbassi</name>
      <email>ali.karbassi@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/69-ucfirst" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor273</id>
    <published>2007-10-04T08:27:43-07:00</published>
    <title>[JavaScript] On Simple Form Validation</title>
    <content type="html">&lt;p&gt;Travis: I love jQuery and all, but why should I include a 14kb file just to do this? It's a waste of load time for the user.&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Ali Karbassi</name>
      <email>ali.karbassi@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/48-simple-form-validation/refactors/273" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor216</id>
    <published>2007-10-02T19:03:38-07:00</published>
    <title>[JavaScript] On Is this year a leap year?</title>
    <content type="html">&lt;p&gt;Going of what &amp;quot;br&amp;quot; said and other people's code, we could do this the following.&lt;/p&gt;

&lt;pre&gt;Object.extend(Date.prototype, {
	isLeap: function()
	{
		return new Date(this.getFullYear(), 2, 0).getDate() == 29;
	}
});&lt;/pre&gt;</content>
    <author>
      <name>Ali Karbassi</name>
      <email>ali.karbassi@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/14-is-this-year-a-leap-year/refactors/216" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code48</id>
    <published>2007-10-02T18:55:19-07:00</published>
    <updated>2010-10-04T11:48:22-07:00</updated>
    <title>[JavaScript] Simple Form Validation</title>
    <content type="html">&lt;p&gt;All this does is check to see if the form fields with the class of &amp;quot;required&amp;quot; have values selected / inputted.&lt;/p&gt;

&lt;p&gt;The submit button should be: &amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;submit&amp;quot; onclick=&amp;quot;javascript:check();&amp;quot; /&amp;gt;&lt;/p&gt;

&lt;pre&gt;## The Code [javascript]
function getElementsByClass(searchClass, node, tag)
{
	var classElements = new Array();
	if ( node == null ) node = document;
	if ( tag == null ) tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp(&amp;quot;(^|\\s)&amp;quot;+searchClass+&amp;quot;(\\s|$)&amp;quot;);
	for (i = 0, j = 0; i &amp;lt; elsLen; i++)
	{
		if ( pattern.test(els[i].className) )
		{
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function check( formName )
{
	var req = getElementsByClass('required', formName.form);
	var err = new Array();
	
	for( var i=0; i &amp;lt; req.length; i++)
	{
		var value = document.getElementById(req[i].htmlFor).value;
		if( value == null || value == '' )
		{
			err.push(req[i].htmlFor);
		}
	}
	
	if( err.length &amp;gt; 0 )
	{
		var txt = 'Please fill in the following fields:' + &amp;quot;\n-&amp;quot; + err.join(&amp;quot;\n-&amp;quot;);
		alert( txt );
		return false;
	}
	else
	{
		formName.form.submit();
		return true;
	}
}

## The HTML [xhtml_1.0]
&amp;lt;!DOCTYPE html PUBLIC &amp;quot;-//W3C//DTD XHTML 1.0 Strict//EN&amp;quot;
	&amp;quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&amp;quot;&amp;gt;

&amp;lt;html xmlns=&amp;quot;http://www.w3.org/1999/xhtml&amp;quot; xml:lang=&amp;quot;en&amp;quot; lang=&amp;quot;en&amp;quot;&amp;gt;
&amp;lt;head&amp;gt;
	&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=utf-8&amp;quot;/&amp;gt;
	&amp;lt;title&amp;gt;Sample Form&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
	&amp;lt;form method=&amp;quot;post&amp;quot; id=&amp;quot;formID&amp;quot; action=&amp;quot;#&amp;quot;&amp;gt;
		&amp;lt;fieldset&amp;gt;
			&amp;lt;legend&amp;gt;Sample Form&amp;lt;/legend&amp;gt;
			&amp;lt;label for=&amp;quot;Username&amp;quot; class=&amp;quot;required&amp;quot;&amp;gt;Username:&amp;lt;/label&amp;gt;
			&amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;Username&amp;quot; name=&amp;quot;Username&amp;quot; /&amp;gt;

			&amp;lt;label for=&amp;quot;Comments&amp;quot;&amp;gt;Comments&amp;lt;/label&amp;gt;
			&amp;lt;textarea name=&amp;quot;Comments&amp;quot; id=&amp;quot;Comments&amp;quot; rows=&amp;quot;10&amp;quot; cols=&amp;quot;40&amp;quot;&amp;gt;&amp;lt;/textarea&amp;gt;

			&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Submit&amp;quot; onclick=&amp;quot;javascript:check(this);&amp;quot; /&amp;gt;
			&amp;lt;input type=&amp;quot;reset&amp;quot; value=&amp;quot;Reset&amp;quot; /&amp;gt;
		&amp;lt;/fieldset&amp;gt;
	&amp;lt;/form&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/pre&gt;</content>
    <author>
      <name>Ali Karbassi</name>
      <email>ali.karbassi@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/48-simple-form-validation" rel="alternate"/>
  </entry>
</feed>

