<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WiseCodes &#187; PHP</title>
	<atom:link href="http://www.wisecodes.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wisecodes.com</link>
	<description>Bringing You The Power of Code !!</description>
	<lastBuildDate>Wed, 01 Sep 2010 19:33:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>The 10 most important skills for future programmers</title>
		<link>http://www.wisecodes.com/2009/09/the-10-most-important-skills-for-future-programmers/</link>
		<comments>http://www.wisecodes.com/2009/09/the-10-most-important-skills-for-future-programmers/#comments</comments>
		<pubDate>Sun, 06 Sep 2009 14:34:27 +0000</pubDate>
		<dc:creator>Venu Thomas</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Agile]]></category>
		<category><![CDATA[Domain]]></category>
		<category><![CDATA[Future]]></category>
		<category><![CDATA[Humman Skills]]></category>
		<category><![CDATA[Hygiene]]></category>
		<category><![CDATA[Important]]></category>
		<category><![CDATA[JAVA]]></category>
		<category><![CDATA[Mobile Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Porgrammers]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[Skills]]></category>
		<category><![CDATA[Web Devlopment]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://www.wisecodes.com/?p=824</guid>
		<description><![CDATA[It is important to ensure that we are benefiting as much as possible when we invest time and effort to train and learn new things. The following list will see the 10 we should learn skills that our curriculum is relevant for the next 5 years. This list is not complete and covers some niche [...]]]></description>
			<content:encoded><![CDATA[<p>It is important to ensure that we are benefiting as much as possible when we invest time and effort to train and learn new things.</p>
<p>The following list will see the 10 we should learn skills that our curriculum is relevant for the next 5 years. This list is not complete and covers some niche markets (such as mainframes). However, if you learn at least seven items in this list you will not miss it.</p>
<h2>1. One of the &#8220;Big 3&#8243; (Java, . NET &amp; PHP)</h2>
<p>Barring a radical change in the world of development (such as an asteroid falling on Redmond), most developers will need to know any of the three major systems development: Java,. NET (VB.NET or C #) or PHP. Nor enough to know the main language. As projects grow and are grabbing more functionality, we will need to know the frameworks and libraries associated with depth.</p>
<h2>2. Rich Internet Applications (RIA &#8211; Rich Internet Applications)</h2>
<p>They can love or hate, but in recent years, Flash is being used for something other than funny animations. Flash also gained additional functionality in the form of Flex and AIR. Competitors of Flash, as JavaFX and Silverlight are also improving in performance. The browsers are improving their JavaScript engine, which is emerging as a web application platform. To make things more complicated, HTML 5 is going to incorporate lots of RIA functionality, including connection to the database, thus the formal seal of the W3C to AJAX. In the near future, have experience of RIA will be a determining factor in our curriculum.</p>
<h2>3. Web Development</h2>
<p>Web development will not disappear in the future. Many developers were happy so far ignored the web, or just staying with &#8220;the basics&#8221; that gave them their framework. But companies are demanding more and more to those who really know how to work with the underlying technologies. So we should improve our knowledge of JavaScript, CSS and HTML to succeed in the next five years.</p>
<h2>4. Web Services</h2>
<p>&#8220;REST or SOAP? JSON or XML? Although the election and the answers depend on the project, it is increasingly difficult to be a developer without having to consume Web Services (even if our development is not a Web application). Even the land area used to be ODBC, COM or RPC are now moving to Web services of some kind. Developers who can not work with Web services will end up relegated to maintenance on legacy code.</p>
<h2>5. Human skills</h2>
<p>There is a trend that has occurred some time ago: the increasing visibility of IT within and outside the organization. The developers are taking more and more meetings that are not development and process for obtaining feedback from them. For example, the CFO can not change the accounting rules without working with IT to update the system. And an operations manager can not change the process of call without IT center update the CRM work-flow. Similarly, customers often need to work directly with development teams to ensure their needs are met. Will it be necessary for all developers to consider how to win friends and influence people? No. But the developers that they will do will be much more valuable to their employers &#8211; and are highly sought after in the market.</p>
<h2>6. A dynamic programming language and / or functional</h2>
<p>Languages like Ruby, Python, F # and Groovy are not yet very popular &#8211; but so are the ideas behind them. For example, the LINQ system. NET is a direct descendant of functional programming techniques. Both Ruby and Python are becoming increasingly popular in some quarters, thanks to the Rails framework and Silverlight respectively. Learn one of these languages will not only improve our curriculum, but also will expand our horizon. All great developers recommend learning at least one dynamic or functional languages to make learning new ways of thinking.</p>
<h2>7. Agile Methodologies</h2>
<p>As time passes, the ideas behind Agile become more defined and better expressed. Many organizations are adopting Agile or proofs of concept for doing Agile. Although Agile is no silver bullet to avoid failure in a project definitely has its place in many projects. Developers who have experience in working and understanding Agile environments will be increasingly in demand in the next five years.</p>
<h2>8. Domain Knowledge</h2>
<p>Hand in hand with the agile methodologies, development teams are increasingly viewed partners in the project definition. This means that developers who understand the problem domain will be able to contribute to the project in a very visible and valuable. With Agile, a developer can say &#8220;From here, we can very easily add this functionality, and you get great value,&#8221; or &#8220;Hey, this requirement is not in keeping with the pattern of use that the logs show. No matter how many developers resist the idea of knowing anything about the problem domain, it is undeniable that more and more organizations prefer (if not even require) developers to at least understand the basics of the business.</p>
<h2>9. &#8220;Hygiene&#8221; development</h2>
<p>Until a few years ago, many (if not all) organizations had no access to bug tracking systems, version control and other tools, all developers are summarized and their preferred IDE. But thanks to the creation of new integrated development environments and the explosion of free software environments of high quality, since there are almost no organizations without these tools. Developers have to know much more than just do a checkout of the code. You need to have a rigorous hygiene habits to ensure they are properly coordinated with the team. The &#8220;solitary programmers&#8221; that keep everything local, non-document changes and others will not be welcome in traditional organizations, and will be aa directly out of place in Agile environments, where you use a strong coordination between equipment to operate.</p>
<h2>10. Mobile Development</h2>
<p>During the late 1990 web development grew and gained widespread adoption, so begin to displace traditional desktop applications. In 2008, development for mobile devices eventually took off, and over the next five years will grow steadily. Of course, there are several approaches to mobile development: web applications designed to run on mobile devices, RIAs aimed at this market, and applications that run directly on the devices. No matter what path we choose, we will serve add mobile development skills to our group.</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.wisecodes.com/2009/09/the-10-most-important-skills-for-future-programmers/" target="_blank"><img src="http://www.wisecodes.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.wisecodes.com/2009/09/the-10-most-important-skills-for-future-programmers/" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.wisecodes.com/2009/09/the-10-most-important-skills-for-future-programmers/feed/</wfw:commentRss>
		<slash:comments>57</slash:comments>
		</item>
		<item>
		<title>PHP on Windows Training Kit (April 2009)</title>
		<link>http://www.wisecodes.com/2009/05/php-on-windows-training-kit-april-2009/</link>
		<comments>http://www.wisecodes.com/2009/05/php-on-windows-training-kit-april-2009/#comments</comments>
		<pubDate>Wed, 13 May 2009 17:19:29 +0000</pubDate>
		<dc:creator>Venu Thomas</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Training]]></category>

		<guid isPermaLink="false">http://www.wisecodes.com/?p=455</guid>
		<description><![CDATA[Now Microsoft has published Training toolkit ie. PHP On Windows Training Kit (April 2009). This is a kit designed to help PHP developers can build applications in this language and platform for Windows and using IIS 7 and SQL Server 2008. The kit includes the following elements: * PHP &#38; SQL Server Demos. * Integrating [...]]]></description>
			<content:encoded><![CDATA[<p>Now Microsoft has published Training toolkit ie. <a href="https://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=c8498c9b-a85a-4afa-90c0-593d0e4850cb" target="_blank">PHP On Windows Training Kit (April 2009)</a>. This is a kit designed to help PHP developers can build applications in this language and platform for Windows and using IIS 7 and SQL Server 2008. The kit includes the following elements:</p>
<p>* PHP &amp; SQL Server Demos.<br />
* Integrating Geo-Spatial SQL Server with PHP.<br />
* SQL Server Reporting Services and PHP.<br />
* PHP &amp; SQL Server Hands On Labs<br />
* Introduction to Using SQL Server with PHP<br />
* Full Text Search Using Office Documents in PHP over.<br />
* PHP on Windows Hands On Labs<br />
* IIS Access Control Features for PHP.<br />
* Media Features Using IIS 7.0 in a PHP Application.<br />
* Troubleshooting PHP.<br />
* Migrating PHP Applications to IIS 7.0.</p>
<p>Link: Via <a href="https://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=c8498c9b-a85a-4afa-90c0-593d0e4850cb" target="_blank">Microsoft</a></p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.wisecodes.com/2009/05/php-on-windows-training-kit-april-2009/" target="_blank"><img src="http://www.wisecodes.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.wisecodes.com/2009/05/php-on-windows-training-kit-april-2009/" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.wisecodes.com/2009/05/php-on-windows-training-kit-april-2009/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Validate: Username, Email Id, Phone No, Zip Code &amp; URL In 5 Languages(JS, C#.Net, VB.Net, JAVA &amp; PHP)</title>
		<link>http://www.wisecodes.com/2009/03/validate-username-email-id-phone-no-zip-code-url-in-5-languages/</link>
		<comments>http://www.wisecodes.com/2009/03/validate-username-email-id-phone-no-zip-code-url-in-5-languages/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 14:23:09 +0000</pubDate>
		<dc:creator>Venu Thomas</dc:creator>
				<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[JAVA]]></category>
		<category><![CDATA[JAVASCRIPT]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[Learn]]></category>

		<guid isPermaLink="false">http://www.code.venuthomas.net/?p=225</guid>
		<description><![CDATA[Validate of Username, Email Id, Phone No, Zip/Postal Code &#38; URL In Javascript, C#.Net, VB.Net, JAVA &#38; PHP ! 1. Validate username: Validate alpha numeric values 2. Validate email addresses : example@domain.com 3. Validate Phone numbers: Validate US phone number eg: 123-456-7890 4. Validate Zip/Postal Codes: Validate US Zip/Postal Code eg: 12345-6789 5. Validate Domain [...]]]></description>
			<content:encoded><![CDATA[<p>Validate of Username, Email Id, Phone No, Zip/Postal Code &amp; URL In Javascript, C#.Net, VB.Net, JAVA &amp; PHP !</p>
<p>1. Validate username: Validate alpha numeric values<br />
2. Validate email addresses : example@domain.com<br />
3. Validate Phone numbers: Validate US phone number eg: 123-456-7890<br />
4. Validate Zip/Postal Codes: Validate US Zip/Postal Code eg: 12345-6789<br />
5. Validate Domain Name eg: http://live.com</p>
<h2>Validate username: Validate alpha numeric values </h2>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code26'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22526"><td class="code" id="p225code26"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> is_valid_username<span style="color: #009900;">&#40;</span>str_username<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #003366; font-weight: bold;">var</span> filter <span style="color: #339933;">=</span> <span style="color: #009966; font-style: italic;">/^([a-zA-Z\s0-9]*)$/</span><span style="color: #339933;">;</span>
 <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>filter.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>str_username<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
 <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>’Wrong username format.’<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #000066; font-weight: bold;">else</span>
 <span style="color: #009900;">&#123;</span>
 <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Username format is ok.'</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code27'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22527"><td class="code" id="p225code27"><pre class="csharp" style="font-family:monospace;"> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Text.RegularExpressions</span><span style="color: #008000;">;</span>
&nbsp;
 <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> is_valid_username<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> str_username<span style="color: #008000;">&#41;</span>
 <span style="color: #008000;">&#123;</span>
 Regex matchRegex <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Regex<span style="color: #008000;">&#40;</span><span style="color: #666666;">@&quot;^[a-zA-Z0-9_]{3,16}$&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
 MatchCollection matches  <span style="color: #008000;">=</span> matchRegex<span style="color: #008000;">.</span><span style="color: #0000FF;">Matches</span><span style="color: #008000;">&#40;</span>str_username<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
 <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span>matches<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">==</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
 <span style="color: #008000;">&#123;</span>
 Response<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Wrong username format.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// In Webserver</span>
 <span style="color: #008080; font-style: italic;">//MessageBox.Show(&quot;Wrong username format.&quot;); //In Windows Form</span>
 <span style="color: #008000;">&#125;</span>
 <span style="color: #0600FF; font-weight: bold;">else</span>
 <span style="color: #008000;">&#123;</span>
 Response<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Username format is ok.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// In Webserver</span>
 <span style="color: #008080; font-style: italic;">//MessageBox.Show(&quot;Username format is ok.&quot;); //In Windows Form</span>
 <span style="color: #008000;">&#125;</span>
 <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code28'); return false;">View Code</a> VBNET</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22528"><td class="code" id="p225code28"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Text</span>.<span style="color: #0000FF;">RegularExpressions</span>
&nbsp;
<span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> is_valid_username<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> str_username <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">Dim</span> matchRegex <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> Regex<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;^[a-zA-Z0-9_]{3,16}$&quot;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">Dim</span> matches <span style="color: #FF8000;">As</span> MatchCollection <span style="color: #008000;">=</span> matchRegex.<span style="color: #0000FF;">Matches</span><span style="color: #000000;">&#40;</span>str_username<span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">If</span> matches.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">Then</span>
        Response.<span style="color: #0600FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Wrong username format.&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008080; font-style: italic;">' In Webserver</span>
        <span style="color: #008080; font-style: italic;">'MessageBox.Show(&quot;Wrong username format.&quot;); 'In Windows Form</span>
    <span style="color: #FF8000;">Else</span>
        Response.<span style="color: #0600FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Username format is ok.&quot;</span><span style="color: #000000;">&#41;</span>    <span style="color: #008080; font-style: italic;">' In Webserver</span>
        <span style="color: #008080; font-style: italic;">'MessageBox.Show(&quot;Username format is ok.&quot;); 'In Windows Form</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code29'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22529"><td class="code" id="p225code29"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.regex.*</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> is_valid_username
<span style="color: #009900;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> str_username<span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
 Pattern p<span style="color: #339933;">=</span>Pattern.<span style="color: #006633;">compile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;^[A-Za-z0-9]+$&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 Matcher m<span style="color: #339933;">=</span>p.<span style="color: #006633;">matcher</span><span style="color: #009900;">&#40;</span>str_username<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000066; font-weight: bold;">boolean</span> matchFound <span style="color: #339933;">=</span> m.<span style="color: #006633;">matches</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>matchFound<span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
 <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Username format is ok.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #000000; font-weight: bold;">else</span>
 <span style="color: #009900;">&#123;</span>
 <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Wrong username format.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code30'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22530"><td class="code" id="p225code30"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">Function</span> is_valid_username<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str_username</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/preg_match"><span style="color: #990000;">preg_match</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^[a-z\d_]{5,20}$/i'</span><span style="color: #339933;">,</span><span style="color: #000088;">$str_username</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Username format is ok.&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #b1b100;">else</span>
 <span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Wrong username format.&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h2>Validate email addresses : example@domain.com </h2>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code31'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22531"><td class="code" id="p225code31"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> is_valid_email<span style="color: #009900;">&#40;</span>str_email_id<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #003366; font-weight: bold;">var</span> filter <span style="color: #339933;">=</span> <span style="color: #009966; font-style: italic;">/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/</span><span style="color: #339933;">;</span>
 <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>filter.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>str_email_id<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
 <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>’Wrong email address format.’<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #000066; font-weight: bold;">else</span>
 <span style="color: #009900;">&#123;</span>
 <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Email address format is ok.'</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code32'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22532"><td class="code" id="p225code32"><pre class="csharp" style="font-family:monospace;"> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Text.RegularExpressions</span><span style="color: #008000;">;</span>
 <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> is_valid_email<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> email_id<span style="color: #008000;">&#41;</span>
 <span style="color: #008000;">&#123;</span>
 Regex matchRegex <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Regex<span style="color: #008000;">&#40;</span><span style="color: #666666;">@&quot;[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9_\-\.]+\.[a-zA-Z]{2,5}&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
 MatchCollection matches  <span style="color: #008000;">=</span> matchRegex<span style="color: #008000;">.</span><span style="color: #0000FF;">Matches</span><span style="color: #008000;">&#40;</span>email_id<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
 <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span>matches<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">==</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
 <span style="color: #008000;">&#123;</span>
 Response<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Wrong email address format.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// In Webserver</span>
 <span style="color: #008080; font-style: italic;">//MessageBox.Show(&quot;Wrong email address format.&quot;); //In Windows Form</span>
 <span style="color: #008000;">&#125;</span>
 <span style="color: #0600FF; font-weight: bold;">else</span>
 <span style="color: #008000;">&#123;</span>
 Response<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Email address format is ok.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// In Webserver</span>
 <span style="color: #008080; font-style: italic;">//MessageBox.Show(&quot;Email address format is ok.&quot;); //In Windows Form</span>
 <span style="color: #008000;">&#125;</span>
 <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code33'); return false;">View Code</a> VBNET</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22533"><td class="code" id="p225code33"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Text</span>.<span style="color: #0000FF;">RegularExpressions</span>
&nbsp;
<span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> is_valid_email<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> email_id <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">Dim</span> matchRegex <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> Regex<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9_\-\.]+\.[a-zA-Z]{2,5}&quot;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">Dim</span> matches <span style="color: #FF8000;">As</span> MatchCollection <span style="color: #008000;">=</span> matchRegex.<span style="color: #0000FF;">Matches</span><span style="color: #000000;">&#40;</span>email_id<span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">If</span> matches.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">Then</span>
        Response.<span style="color: #0600FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Wrong email address format.&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008080; font-style: italic;">' In Webserver</span>
        <span style="color: #008080; font-style: italic;">'MessageBox.Show(&quot;Wrong email address format.&quot;); 'In Windows Form</span>
    <span style="color: #FF8000;">Else</span>
        Response.<span style="color: #0600FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Email address format is ok.&quot;</span><span style="color: #000000;">&#41;</span>    <span style="color: #008080; font-style: italic;">' In Webserver</span>
        <span style="color: #008080; font-style: italic;">'MessageBox.Show(&quot;Email address format is ok.&quot;); 'In Windows Form</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code34'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22534"><td class="code" id="p225code34"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.regex.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> is_valid_email
<span style="color: #009900;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> str_email_id<span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
 Pattern p<span style="color: #339933;">=</span>Pattern.<span style="color: #006633;">compile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;[a-zA-Z]*[0-9]*@[a-zA-Z]*.[a-zA-Z]*&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 Matcher m<span style="color: #339933;">=</span>p.<span style="color: #006633;">matcher</span><span style="color: #009900;">&#40;</span>str_email_id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000066; font-weight: bold;">boolean</span> matchFound <span style="color: #339933;">=</span> m.<span style="color: #006633;">matches</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>matchFound<span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
 <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Email address format is ok.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #000000; font-weight: bold;">else</span>
 <span style="color: #009900;">&#123;</span>
 <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Wrong email address format.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code35'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22535"><td class="code" id="p225code35"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">Function</span> is_valid_email<span style="color: #009900;">&#40;</span><span style="color: #000088;">$email_id</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/preg_match"><span style="color: #990000;">preg_match</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/'</span><span style="color: #339933;">,</span><span style="color: #000088;">$email_id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Email address format is ok.&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #b1b100;">else</span>
 <span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Wrong email address format.&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h2><strong>Validate Phone numbers: Validate US phone number eg: 123-456-7890</strong></h2>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code36'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22536"><td class="code" id="p225code36"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> is_valid_phone_no<span style="color: #009900;">&#40;</span>str_phone_no<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #003366; font-weight: bold;">var</span> filter <span style="color: #339933;">=</span>  <span style="color: #009966; font-style: italic;">/^((\+?1-)?\d\d\d-)?\d\d\d-\d\d\d\d$/</span><span style="color: #339933;">;</span>
 <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>filter.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>str_phone_no<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
 <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>’Wrong phone number format.’<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #000066; font-weight: bold;">else</span>
 <span style="color: #009900;">&#123;</span>
 <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Phone number format is ok.'</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code37'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22537"><td class="code" id="p225code37"><pre class="csharp" style="font-family:monospace;"> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Text.RegularExpressions</span><span style="color: #008000;">;</span>
&nbsp;
 <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> is_valid_phone_no<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> str_phone_no<span style="color: #008000;">&#41;</span>
 <span style="color: #008000;">&#123;</span>
 Regex matchRegex <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Regex<span style="color: #008000;">&#40;</span><span style="color: #666666;">@&quot;\d{3}-\d{3}-\d{4}$&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
 MatchCollection matches  <span style="color: #008000;">=</span> matchRegex<span style="color: #008000;">.</span><span style="color: #0000FF;">Matches</span><span style="color: #008000;">&#40;</span>str_phone_no<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
 <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span>matches<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">==</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
 <span style="color: #008000;">&#123;</span>
 Response<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Wrong phone number format.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// In Webserver</span>
 <span style="color: #008080; font-style: italic;">//MessageBox.Show(&quot;Wrong phone number format.&quot;); //In Windows Form</span>
 <span style="color: #008000;">&#125;</span>
 <span style="color: #0600FF; font-weight: bold;">else</span>
 <span style="color: #008000;">&#123;</span>
 Response<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Phone number format is ok.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// In Webserver</span>
 <span style="color: #008080; font-style: italic;">//MessageBox.Show(&quot;Phone number format is ok.&quot;); //In Windows Form</span>
 <span style="color: #008000;">&#125;</span>
 <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code38'); return false;">View Code</a> VBNET</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22538"><td class="code" id="p225code38"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Text</span>.<span style="color: #0000FF;">RegularExpressions</span>
<span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> is_valid_phone_no<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> str_phone_no <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">Dim</span> matchRegex <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> Regex<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;\d{3}-\d{3}-\d{4}$&quot;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">Dim</span> matches <span style="color: #FF8000;">As</span> MatchCollection <span style="color: #008000;">=</span> matchRegex.<span style="color: #0000FF;">Matches</span><span style="color: #000000;">&#40;</span>str_phone_no<span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">If</span> matches.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">Then</span>
        Response.<span style="color: #0600FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Wrong phone number format.&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008080; font-style: italic;">' In Webserver</span>
        <span style="color: #008080; font-style: italic;">'MessageBox.Show(&quot;Wrong phone number format.&quot;); 'In Windows Form</span>
    <span style="color: #FF8000;">Else</span>
        Response.<span style="color: #0600FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Phone number format is ok.&quot;</span><span style="color: #000000;">&#41;</span>    <span style="color: #008080; font-style: italic;">' In Webserver</span>
        <span style="color: #008080; font-style: italic;">'MessageBox.Show(&quot;Phone number format is ok.&quot;); 'In Windows Form</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code39'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22539"><td class="code" id="p225code39"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.regex.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> is_valid_phone_no
<span style="color: #009900;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> str_phone_no<span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
 Pattern p<span style="color: #339933;">=</span>Pattern.<span style="color: #006633;">compile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;^<span style="color: #000099; font-weight: bold;">\\</span>(?(<span style="color: #000099; font-weight: bold;">\\</span>d{3})<span style="color: #000099; font-weight: bold;">\\</span>)?[- ]?(<span style="color: #000099; font-weight: bold;">\\</span>d{3})[- ]?(<span style="color: #000099; font-weight: bold;">\\</span>d{4})$&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 Matcher m<span style="color: #339933;">=</span>p.<span style="color: #006633;">matcher</span><span style="color: #009900;">&#40;</span>str_phone_no<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000066; font-weight: bold;">boolean</span> matchFound <span style="color: #339933;">=</span> m.<span style="color: #006633;">matches</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>matchFound<span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
 <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Phone number format is ok.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #000000; font-weight: bold;">else</span>
 <span style="color: #009900;">&#123;</span>
 <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Wrong phone number format.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code40'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22540"><td class="code" id="p225code40"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">Function</span> is_valid_phone_no<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str_phone_no</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/preg_match"><span style="color: #990000;">preg_match</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/\(?\d{3}\)?[-\s.]?\d{3}[-\s.]\d{4}/x'</span><span style="color: #339933;">,</span><span style="color: #000088;">$str_phone_no</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Phone number format is ok.&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #b1b100;">else</span>
 <span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Wrong phone number format.&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h2>Validate Zip/Postal Codes: Validate US Zip/Postal Code eg: 12345-6789</h2>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code41'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22541"><td class="code" id="p225code41"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> is_valid_zip_code<span style="color: #009900;">&#40;</span>str_zip_code<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #003366; font-weight: bold;">var</span> filter <span style="color: #339933;">=</span>  <span style="color: #009966; font-style: italic;">/^\d\d\d\d\d-\d\d\d\d$/</span><span style="color: #339933;">;</span>
 <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>filter.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>str_zip_code<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
 <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>’Wrong Zip<span style="color: #339933;">/</span>Postal Code format.’<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #000066; font-weight: bold;">else</span>
 <span style="color: #009900;">&#123;</span>
 <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Zip/Postal Code format is ok.'</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code42'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22542"><td class="code" id="p225code42"><pre class="csharp" style="font-family:monospace;"> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Text.RegularExpressions</span><span style="color: #008000;">;</span>
&nbsp;
 <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> is_valid_zip_code<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> str_zip_code<span style="color: #008000;">&#41;</span>
 <span style="color: #008000;">&#123;</span>
 Regex matchRegex <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Regex<span style="color: #008000;">&#40;</span><span style="color: #666666;">@&quot;\d{5}-\d{4}$&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
 MatchCollection matches  <span style="color: #008000;">=</span> matchRegex<span style="color: #008000;">.</span><span style="color: #0000FF;">Matches</span><span style="color: #008000;">&#40;</span>str_zip_code<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
 <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span>matches<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">==</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
 <span style="color: #008000;">&#123;</span>
 Response<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Wrong Zip/Postal Code format.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// In Webserver</span>
 <span style="color: #008080; font-style: italic;">//MessageBox.Show(&quot;Wrong Zip/Postal Code format.&quot;); //In Windows Form</span>
 <span style="color: #008000;">&#125;</span>
 <span style="color: #0600FF; font-weight: bold;">else</span>
 <span style="color: #008000;">&#123;</span>
 Response<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Zip/Postal Code format is ok.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// In Webserver</span>
 <span style="color: #008080; font-style: italic;">//MessageBox.Show(&quot;Zip/Postal Code format is ok.&quot;); //In Windows Form</span>
 <span style="color: #008000;">&#125;</span>
 <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code43'); return false;">View Code</a> VBNET</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22543"><td class="code" id="p225code43"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Text</span>.<span style="color: #0000FF;">RegularExpressions</span>
<span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> is_valid_zip_code<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> str_zip_code <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">Dim</span> matchRegex <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> Regex<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;\d{5}-\d{4}$&quot;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">Dim</span> matches <span style="color: #FF8000;">As</span> MatchCollection <span style="color: #008000;">=</span> matchRegex.<span style="color: #0000FF;">Matches</span><span style="color: #000000;">&#40;</span>str_zip_code<span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">If</span> matches.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">Then</span>
        Response.<span style="color: #0600FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Wrong Zip/Postal Code format.&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008080; font-style: italic;">' In Webserver</span>
        <span style="color: #008080; font-style: italic;">'MessageBox.Show(&quot;Wrong Zip/Postal Code format.&quot;); 'In Windows Form</span>
    <span style="color: #FF8000;">Else</span>
        Response.<span style="color: #0600FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Zip/Postal Code format is ok.&quot;</span><span style="color: #000000;">&#41;</span>    <span style="color: #008080; font-style: italic;">' In Webserver</span>
        <span style="color: #008080; font-style: italic;">'MessageBox.Show(&quot;Zip/Postal Code format is ok.&quot;); 'In Windows Form</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code44'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22544"><td class="code" id="p225code44"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.regex.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> is_valid_zip_code
<span style="color: #009900;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> str_zip_code<span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
 Pattern p<span style="color: #339933;">=</span>Pattern.<span style="color: #006633;">compile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;^(<span style="color: #000099; font-weight: bold;">\\</span>d{5})[- ]?(<span style="color: #000099; font-weight: bold;">\\</span>d{4})$&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 Matcher m<span style="color: #339933;">=</span>p.<span style="color: #006633;">matcher</span><span style="color: #009900;">&#40;</span>str_zip_code<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000066; font-weight: bold;">boolean</span> matchFound <span style="color: #339933;">=</span> m.<span style="color: #006633;">matches</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>matchFound<span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
 <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Zip/Postal Code format is ok.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #000000; font-weight: bold;">else</span>
 <span style="color: #009900;">&#123;</span>
 <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Wrong Zip/Postal Code format.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code45'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22545"><td class="code" id="p225code45"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">Function</span> is_valid_zip_code<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str_zip_code</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/preg_match"><span style="color: #990000;">preg_match</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^([0-9]{5})(-[0-9]{4})?$/i'</span><span style="color: #339933;">,</span><span style="color: #000088;">$str_zip_code</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Zip/Postal Code format is ok.&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #b1b100;">else</span>
 <span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Wrong Zip/Postal Code format.&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h2>Validate  Domain Name eg: http://live.com</h2>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code46'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22546"><td class="code" id="p225code46"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> is_valid_url<span style="color: #009900;">&#40;</span>str_url<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #003366; font-weight: bold;">var</span> filter <span style="color: #339933;">=</span>   <span style="color: #009966; font-style: italic;">/^(ht|f)tps?:\/\/[a-z0-9-\.]+\.[a-z]{2,4}\/?([^\s&amp;lt;&amp;gt;\#%&quot;\,\{\}\\|\\\^\[\]`]+)?$/</span>
 <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>filter.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>str_url<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
 <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>’Wrong URL format.’<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #000066; font-weight: bold;">else</span>
 <span style="color: #009900;">&#123;</span>
 <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'URL format is ok.'</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code47'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22547"><td class="code" id="p225code47"><pre class="csharp" style="font-family:monospace;"> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Text.RegularExpressions</span><span style="color: #008000;">;</span>
 <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> is_valid_url<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> str_url<span style="color: #008000;">&#41;</span>
 <span style="color: #008000;">&#123;</span>
Regex matchRegex <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Regex<span style="color: #008000;">&#40;</span><span style="color: #666666;">@&quot;(http|https)://([\w-]+\.)+[\w-]+(/[\w- ./?%&amp;amp;=]*)?&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
 MatchCollection matches  <span style="color: #008000;">=</span> matchRegex<span style="color: #008000;">.</span><span style="color: #0000FF;">Matches</span><span style="color: #008000;">&#40;</span>str_url<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
 <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span>matches<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">==</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
 <span style="color: #008000;">&#123;</span>
 Response<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Wrong URL format.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// In Webserver</span>
 <span style="color: #008080; font-style: italic;">//MessageBox.Show(&quot;Wrong URL format.&quot;); //In Windows Form</span>
 <span style="color: #008000;">&#125;</span>
 <span style="color: #0600FF; font-weight: bold;">else</span>
 <span style="color: #008000;">&#123;</span>
 Response<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;URL format is ok.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// In Webserver</span>
 <span style="color: #008080; font-style: italic;">//MessageBox.Show(&quot;URL format is ok.&quot;); //In Windows Form</span>
 <span style="color: #008000;">&#125;</span>
 <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code48'); return false;">View Code</a> VBNET</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22548"><td class="code" id="p225code48"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Text</span>.<span style="color: #0000FF;">RegularExpressions</span>
&nbsp;
<span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> is_valid_url<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> str_url <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">Dim</span> matchRegex <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> Regex<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;(http|https)://([\w-]+\.)+[\w-]+(/[\w- ./?%&amp;amp;=]*)?&quot;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">Dim</span> matches <span style="color: #FF8000;">As</span> MatchCollection <span style="color: #008000;">=</span> matchRegex.<span style="color: #0000FF;">Matches</span><span style="color: #000000;">&#40;</span>str_url<span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">If</span> matches.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">Then</span>
        Response.<span style="color: #0600FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Wrong URL format.&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008080; font-style: italic;">' In Webserver</span>
        <span style="color: #008080; font-style: italic;">'MessageBox.Show(&quot;Wrong URL format.&quot;); 'In Windows Form</span>
    <span style="color: #FF8000;">Else</span>
        Response.<span style="color: #0600FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;URL format is ok.&quot;</span><span style="color: #000000;">&#41;</span>    <span style="color: #008080; font-style: italic;">' In Webserver</span>
        <span style="color: #008080; font-style: italic;">'MessageBox.Show(&quot;URL format is ok.&quot;); 'In Windows Form</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code49'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22549"><td class="code" id="p225code49"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.regex.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> is_valid_url
<span style="color: #009900;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> str_url<span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
 Pattern p<span style="color: #339933;">=</span>Pattern.<span style="color: #006633;">compile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;(http|https)://([<span style="color: #000099; font-weight: bold;">\w</span>-]+<span style="color: #000099; font-weight: bold;">\.</span>)+[<span style="color: #000099; font-weight: bold;">\w</span>-]+(/[<span style="color: #000099; font-weight: bold;">\w</span>- ./?%&amp;amp;=]*)?&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 Matcher m<span style="color: #339933;">=</span>p.<span style="color: #006633;">matcher</span><span style="color: #009900;">&#40;</span>str_url<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000066; font-weight: bold;">boolean</span> matchFound <span style="color: #339933;">=</span> m.<span style="color: #006633;">matches</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>matchFound<span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
 <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;URL format is ok.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #000000; font-weight: bold;">else</span>
 <span style="color: #009900;">&#123;</span>
 <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Wrong URL format.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code50'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22550"><td class="code" id="p225code50"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">Function</span> is_valid_url<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str_url</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/preg_match"><span style="color: #990000;">preg_match</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^([0-9]{5})(-[0-9]{4})?$/i'</span><span style="color: #339933;">,</span><span style="color: #000088;">$str_url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;URL format is ok.&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #b1b100;">else</span>
 <span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Wrong URL format.&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.wisecodes.com/2009/03/validate-username-email-id-phone-no-zip-code-url-in-5-languages/" target="_blank"><img src="http://www.wisecodes.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.wisecodes.com/2009/03/validate-username-email-id-phone-no-zip-code-url-in-5-languages/" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.wisecodes.com/2009/03/validate-username-email-id-phone-no-zip-code-url-in-5-languages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create PHP Desktop Applications &#8211; Calculator</title>
		<link>http://www.wisecodes.com/2009/03/create-php-desktop-applications-calculator/</link>
		<comments>http://www.wisecodes.com/2009/03/create-php-desktop-applications-calculator/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 20:21:41 +0000</pubDate>
		<dc:creator>Venu Thomas</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Application]]></category>

		<guid isPermaLink="false">http://www.code.venuthomas.net/?p=121</guid>
		<description><![CDATA[Introduction As for PHP, Web is already known as a server-side language for creating applications, PHP-GTK2 and make use of the extension, PHP allows you to create applications that run on the desktop. In this paper, the PHP-GTK2 try to create a simple calculator for desktop use. Audience If you want to create PHP applications [...]]]></description>
			<content:encoded><![CDATA[<h3><strong>Introduction</strong></h3>
<p>As for PHP, Web is already known as a server-side language for creating applications, PHP-GTK2 and make use of the extension, PHP allows you to create applications that run on the desktop. In this paper, the PHP-GTK2 try to create a simple calculator for desktop use.</p>
<h3><strong>Audience</strong></h3>
<p>If you want to create PHP applications on the desktop</p>
<h3><strong>Environmental Building</strong></h3>
<p>Target OS is, Linux and Windows.</p>
<p>PHP-GTK2 is, <a href="http://gtk.php.net/" target="_blank">PHP-GTK can be downloaded for free from our site.</a></p>
<p>For Windows, &#8220;php-gtk-2.**.**-win32-nts.zip&#8221; to download and unzip the file.</p>
<p>Basic configuration is at least close.</p>
<h3><strong>Sample program &#8220;Simple Calculator&#8221;</strong></h3>
<p>Then use the PHP-GTK2, let&#8217;s create a simple calculator. The following shows the source.</p>
<p>File name: calculator.php</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p121code60'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12160"><td class="code" id="p121code60"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span> php
<span style="color: #000000; font-weight: bold;">class</span> Calc <span style="color: #009900;">&#40;</span>
<span style="color: #000000; font-weight: bold;">private</span> $ txt_1<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> $ txt_2<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> $ txt_3<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> $ tblTable<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> $ hbox_1<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> $ wnd1<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> $ cboCBox<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> $ calc_btn<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>
<span style="color: #339933;">/</span> <span style="color: #339933;">/</span> Initialize the text box <span style="color: #b1b100;">for</span> numeric input
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">txt_1</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GtkEntry <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">txt_2</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GtkEntry <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">/</span> <span style="color: #339933;">/</span> Initialize display box solution <span style="color: #b1b100;">for</span>
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">txt_3</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GtkEntry <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">/</span> <span style="color: #339933;">/</span> Adjust the width of <a href="http://www.php.net/each"><span style="color: #990000;">each</span></a> text box<span style="color: #339933;">,</span>
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">txt_1</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">set_width_chars</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">txt_2</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">set_width_chars</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">txt_3</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">set_width_chars</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #339933;">/</span> <span style="color: #339933;">/</span> Initialize the cboCBox box selection operator
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">cboCBox</span> <span style="color: #339933;">=</span> GtkcboCBoxBox<span style="color: #339933;">::</span> <span style="color: #004000;">new_text</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">cboCBox</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">insert_text</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;+&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">cboCBox</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">insert_text</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span> <span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;-&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">cboCBox</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">insert_text</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span> <span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;×&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">cboCBox</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">insert_text</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span> <span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;÷&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Appear to <span style="color: #666666; font-style: italic;">//&quot;+&quot; initial</span>
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">cboCBox</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">set_active</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #339933;">/</span> <span style="color: #339933;">/</span> Initialize the calculation button
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">calc_btn</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GtkButton <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;=&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #339933;">/</span> <span style="color: #339933;">/</span> Assign the event listener
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">calc_btn</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">connect_simple</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;clicked&quot;</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a> <span style="color: #009900;">&#40;</span>$ this<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;calcHandler&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #339933;">/</span> <span style="color: #339933;">/</span> Initialize the table
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">tblTable</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GtkTable <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">/</span> <span style="color: #339933;">/</span> Place the components on the table
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">tblTable</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">attach</span> <span style="color: #009900;">&#40;</span>$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">txt_1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">tblTable</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">attach</span> <span style="color: #009900;">&#40;</span>$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">cboCBox</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">tblTable</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">attach</span> <span style="color: #009900;">&#40;</span>$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">txt_2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">tblTable</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">attach</span> <span style="color: #009900;">&#40;</span>$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">calc_btn</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">tblTable</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">attach</span> <span style="color: #009900;">&#40;</span>$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">txt_3</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">hbox_1</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Gtkhbox_1 <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">hbox_1</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">pack_start</span> <span style="color: #009900;">&#40;</span>$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">tblTable</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">wnd1</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GtkWindow <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">wnd1</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">add</span> <span style="color: #009900;">&#40;</span>$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">hbox_1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">wnd1</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">set_title</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;PHP Calculator&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">wnd1</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">show_all</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Gtk<span style="color: #339933;">::</span> <span style="color: #004000;">main</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> calcHandler <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>
$ num1 <span style="color: #339933;">=</span> <a href="http://www.php.net/doubleval"><span style="color: #990000;">doubleval</span></a> <span style="color: #009900;">&#40;</span>$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">txt_1</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">get_text</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$ num2 <span style="color: #339933;">=</span> <a href="http://www.php.net/doubleval"><span style="color: #990000;">doubleval</span></a> <span style="color: #009900;">&#40;</span>$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">txt_2</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">get_text</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span>$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">cboCBox</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">get_active</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>
<span style="color: #339933;">/</span> <span style="color: #339933;">/</span> Add
<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">:</span>
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">txt_3</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">set_text</span> <span style="color: #009900;">&#40;</span>$ num1 <span style="color: #339933;">+</span> $ num2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
<span style="color: #339933;">/</span> <span style="color: #339933;">/</span> Subtraction
<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span>
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">txt_3</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">set_text</span> <span style="color: #009900;">&#40;</span>$ num1 <span style="color: #339933;">-</span> $ num2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
<span style="color: #339933;">/</span> <span style="color: #339933;">/</span> Multiplication
<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">:</span>
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">txt_3</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">set_text</span> <span style="color: #009900;">&#40;</span>$ num1 <span style="color: #339933;">*</span> $ num2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
<span style="color: #339933;">/</span> <span style="color: #339933;">/</span> Division <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">txt_3</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">set_text</span> <span style="color: #009900;">&#40;</span>$ num1 <span style="color: #339933;">/</span> $ num2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span>
<span style="color: #339933;">/</span> <span style="color: #339933;">/</span> Calc<span style="color: #339933;">,</span> create an instance of the <span style="color: #000000; font-weight: bold;">class</span>
&nbsp;
$ calc <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Calc <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3><strong>Run the application</strong></h3>
<p>Let&#8217;s run this application. Open a command prompt, when you could just download the folder php-gtk2. Then, please run the following command:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p121code61'); return false;">View Code</a> TXT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12161"><td class="code" id="p121code61"><pre class="txt" style="font-family:monospace;">C:\php-gtk2&gt; php.exe calculator.php</pre></td></tr></table></div>

<p><strong><em>Result</em></strong></p>
<p><img class="alignnone size-full wp-image-122" title="PHP App" src="http://www.wisecodes.com/wp-content/uploads/2009/03/fig01.gif" alt="PHP App" /></p>
<p>If you want to quit the application, or applications [×] button on the command line [Ctr] + [C] Please run the shortcut key.</p>
<h3><strong>Commentary</strong></h3>
<p>Calc components are defined in the class.</p>
<p style="padding-left: 30px;">
Components used in this<br />
<em><strong>GtkEntry</strong></em> Text box.<br />
<em><strong>GtkComboBox</strong></em> Combo box.<br />
<strong><em>GtkButton</em></strong> Button.<br />
<em><strong>GtkTable</strong></em> Table. Placing a child in a grid component.<br />
<em><strong>GtkHBox</strong></em> Horizontal box to hold the table.<br />
<em><strong>GtkWindow</strong></em> Window to store the horizontal box.</p>
<p>GtkEntry and GtkComboBox, GtkButton and small components, GtkTable and place it in a container. To create a GtkTable this, new GtkTable(1,5) and a vertical length, the length of the next five and a specified grid. GtkTable to the placement of components, as follows: attach use the function.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p121code62'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12162"><td class="code" id="p121code62"><pre class="php" style="font-family:monospace;">$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">tblTable</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">attach</span> <span style="color: #009900;">&#40;</span>$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">txt_1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Then put the components placed GtkHBox GtkTable objects. GtkHBox is the horizontal component of the box. The horizontal box is placed in the following pack_start use the function.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p121code63'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12163"><td class="code" id="p121code63"><pre class="php" style="font-family:monospace;">$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">hbox_1</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">pack_start</span> <span style="color: #009900;">&#40;</span>$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">tblTable</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>In addition, the box GtkHBox add this add to place a GtkWindow object.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p121code64'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12164"><td class="code" id="p121code64"><pre class="php" style="font-family:monospace;">$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">wnd1</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">add</span> <span style="color: #009900;">&#40;</span>$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">hbox_1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>To set the title of the GtkWindow, set_title function.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p121code65'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12165"><td class="code" id="p121code65"><pre class="php" style="font-family:monospace;">$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">wnd1</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">set_title</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;PHP Calculator&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Also, [=] to make the calculation for the function is called when pressing the button below.</p>
<p>$ this-&gt; calc_btn-&gt; connect_simple ( &#8220;clicked&#8221;, array ($ this, &#8220;calcHandler&#8221;));<br />
Signal &#8220;clicked&#8221;, ie when I click &#8220;calcHandler&#8221; means that the function is called.</p>
<p>calcHandler Let&#8217;s look at the contents of the function.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p121code66'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12166"><td class="code" id="p121code66"><pre class="php" style="font-family:monospace;">$ num1 <span style="color: #339933;">=</span> <a href="http://www.php.net/doubleval"><span style="color: #990000;">doubleval</span></a> <span style="color: #009900;">&#40;</span>$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">txt_1</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">get_text</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$ num2 <span style="color: #339933;">=</span> <a href="http://www.php.net/doubleval"><span style="color: #990000;">doubleval</span></a> <span style="color: #009900;">&#40;</span>$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">txt_2</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">get_text</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>txt_1, txt_2 the figures obtained in doubleval to quantify explicitly the function, each variable $ $num1 $ $num2 assigns.</p>
<p>Then, the index of the operator is selected in the combo box of the operator get_active Get function.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p121code67'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12167"><td class="code" id="p121code67"><pre class="php" style="font-family:monospace;">$ this<span style="color: #339933;">-&gt;</span> <span style="color: #004000;">cboCBox</span><span style="color: #339933;">-&gt;</span> <span style="color: #004000;">get_active</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>And in this case, the index</p>
<p>0 addition, if<br />
If a subtraction<br />
If you multiply two<br />
If the three division<br />
Has been set.</p>
<p>Calc Thus we complete the application to generate the last instance of the class.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p121code68'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12168"><td class="code" id="p121code68"><pre class="php" style="font-family:monospace;">$ calc <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Calc <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>Conclusion</h3>
<p>This time I made a PHP-GTK2 applications running on their desktop calculator use. PHP-GTK in the rich component than what&#8217;s used.</p>
<p>PHP is a desktop application that is not made aware of the opportunity that this PHP-GTK2 to even try to challenge?</p>
<p>It may spread to new worlds.</p>
<h3>References</h3>
<h4>
<a href="http://gtk.php.net/manual1/en/userguide.php" target="_blank">PHP-GTK user guide</a></h4>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.wisecodes.com/2009/03/create-php-desktop-applications-calculator/" target="_blank"><img src="http://www.wisecodes.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.wisecodes.com/2009/03/create-php-desktop-applications-calculator/" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.wisecodes.com/2009/03/create-php-desktop-applications-calculator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ajax Based Search Engine With PHP and XML</title>
		<link>http://www.wisecodes.com/2009/02/ajax-based-search-engine-with-php-and-xml/</link>
		<comments>http://www.wisecodes.com/2009/02/ajax-based-search-engine-with-php-and-xml/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 19:52:18 +0000</pubDate>
		<dc:creator>Venu Thomas</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JAVASCRIPT]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.code.venuthomas.net/?p=12</guid>
		<description><![CDATA[Here Sample code of Ajax based search engine with PHP and XML  Live Preview          Download Code   This is the Javascript Code : ?View Code JAVASCRIPT/* &#38;lt;--------------------------&#38;gt; */ /* XMLHTTPRequest Enable */ /* &#38;lt;--------------------------&#38;gt; */ function createObject&#40;&#41; &#123; var request_type; var browser = navigator.appName; if&#40;browser == &#34;Microsoft Internet Explorer&#34;&#41;&#123; request_type = new ActiveXObject&#40;&#34;Microsoft.XMLHTTP&#34;&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>Here Sample code of Ajax based search engine with PHP and XML</p>
<p><span style="color: #000000; text-decoration: none;"><span style="color: #000000; text-decoration: none;"><span style="color: #000000; text-decoration: none;"><a href="http://code.venuthomas.net/Code/Ajax_SearchEngine/html_Search.html" target="_blank"><img class="alignnone size-full wp-image-18" title="live_preview" src="http://www.wisecodes.com/wp-content/uploads/2009/02/live_preview.png" alt="live_preview" width="32" height="32" /> Live Preview</a><span style="color: #000000; text-decoration: none;">          </span><a href="http://code.venuthomas.net/Code/Ajax_SearchEngine/AjaxSearchEngine.zip" target="_blank"><img class="alignnone size-full wp-image-29" title="download" src="http://www.wisecodes.com/wp-content/uploads/2009/02/download.gif" alt="download" width="32" height="35" /></a><span style="color: #000000; text-decoration: none;"><a href="http://code.venuthomas.net/Code/Ajax_SearchEngine/AjaxSearchEngine.zip" target="_blank">Download Code</a></span></span></span></span></p>
<p> </p>
<p><strong>This is the Javascript Code :</strong></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p12code71'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1271"><td class="code" id="p12code71"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* &amp;lt;--------------------------&amp;gt; */</span>
<span style="color: #009966; font-style: italic;">/* XMLHTTPRequest Enable		*/</span>
<span style="color: #009966; font-style: italic;">/* &amp;lt;--------------------------&amp;gt; */</span>
<span style="color: #003366; font-weight: bold;">function</span> createObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003366; font-weight: bold;">var</span> request_type<span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> browser <span style="color: #339933;">=</span> navigator.<span style="color: #660066;">appName</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>browser <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;Microsoft Internet Explorer&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
request_type <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> ActiveXObject<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Microsoft.XMLHTTP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
request_type <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> XMLHttpRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">return</span> request_type<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> http <span style="color: #339933;">=</span> createObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009966; font-style: italic;">/* &amp;lt;--------------------------&amp;gt; */</span>
<span style="color: #009966; font-style: italic;">/* 		SEARCH				   */</span>
<span style="color: #009966; font-style: italic;">/* &amp;lt;--------------------------&amp;gt; */</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> fnSearchName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
txtInput<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">encodeURI</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'txtInput'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'divmsg'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">display</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;block&quot;</span><span style="color: #339933;">;</span>
document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'divmsg'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Searching for &lt;strong&gt;&quot;</span> <span style="color: #339933;">+</span> txtInput<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/strong&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Set te random number to add to URL request</span>
nocache <span style="color: #339933;">=</span> Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
http.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'get'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'php_Search.php?name='</span><span style="color: #339933;">+</span>txtInput<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;amp;nocache = '</span><span style="color: #339933;">+</span>nocache<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
http.<span style="color: #660066;">onreadystatechange</span> <span style="color: #339933;">=</span> fnSearchNameReply<span style="color: #339933;">;</span>
http.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #003366; font-weight: bold;">function</span> fnSearchNameReply<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> response <span style="color: #339933;">=</span> http.<span style="color: #660066;">responseText</span><span style="color: #339933;">;</span>
	document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'divResult'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span><span style="color: #339933;">=</span>response<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>This is the PHP Code :</strong></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p12code72'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1272"><td class="code" id="p12code72"><pre class="php" style="font-family:monospace;">load<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;NameList.xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$x</span><span style="color: #339933;">=</span><span style="color: #000088;">$xmlDoc</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>getElementsByTagName<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'NAME'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span><span style="color: #000088;">$x</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>length<span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">//Process only element nodes</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>item<span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>nodeType<span style="color: #339933;">==</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>item<span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>childNodes<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>item<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>nodeValue <span style="color: #339933;">==</span> <span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$y</span><span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>item<span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>parentNode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$cd</span><span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$y</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>childNodes<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span><span style="color: #000088;">$cd</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>length<span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">//Process only element nodes</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$cd</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>item<span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>nodeType<span style="color: #339933;">==</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cd</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>item<span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>nodeName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cd</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>item<span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>childNodes<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>item<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>nodeValue<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.wisecodes.com/2009/02/ajax-based-search-engine-with-php-and-xml/" target="_blank"><img src="http://www.wisecodes.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.wisecodes.com/2009/02/ajax-based-search-engine-with-php-and-xml/" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.wisecodes.com/2009/02/ajax-based-search-engine-with-php-and-xml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

