<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Phone number validation with jquery</title>
	<atom:link href="http://www.scriptygoddess.com/archives/2008/05/03/phone-number-validation-with-jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scriptygoddess.com/archives/2008/05/03/phone-number-validation-with-jquery/</link>
	<description></description>
	<lastBuildDate>Tue, 16 Mar 2010 19:26:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: ArticleSave :: Uncategorized :: Happy 3rd Birthday, jQuery</title>
		<link>http://www.scriptygoddess.com/archives/2008/05/03/phone-number-validation-with-jquery/comment-page-1/#comment-618263</link>
		<dc:creator>ArticleSave :: Uncategorized :: Happy 3rd Birthday, jQuery</dc:creator>
		<pubDate>Fri, 16 Jan 2009 07:07:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/?p=1517#comment-618263</guid>
		<description>[...] a developer and you haven&#8217;t tried out jQuery yet - you probably should. As Jennifer Stuart wrote when she finally did this Spring, &#8220;Why I didn&#8217;t jump on this bandwagon sooner, [...]</description>
		<content:encoded><![CDATA[<p>[...] a developer and you haven&#039;t tried out jQuery yet &#8211; you probably should. As Jennifer Stuart wrote when she finally did this Spring, &#034;Why I didn&#039;t jump on this bandwagon sooner, [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jQuery 3 ?? at ?????????????</title>
		<link>http://www.scriptygoddess.com/archives/2008/05/03/phone-number-validation-with-jquery/comment-page-1/#comment-618154</link>
		<dc:creator>jQuery 3 ?? at ?????????????</dc:creator>
		<pubDate>Thu, 15 Jan 2009 06:51:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/?p=1517#comment-618154</guid>
		<description>[...] jQuery????????Jennifer Stuart ???????? JavaScript ????????????????????????????? jQuery ??????? [...]</description>
		<content:encoded><![CDATA[<p>[...] jQuery????????Jennifer Stuart ???????? JavaScript ????????????????????????????? jQuery ??????? [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: brindle</title>
		<link>http://www.scriptygoddess.com/archives/2008/05/03/phone-number-validation-with-jquery/comment-page-1/#comment-596385</link>
		<dc:creator>brindle</dc:creator>
		<pubDate>Tue, 16 Sep 2008 07:00:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/?p=1517#comment-596385</guid>
		<description>Hey Scripty,

Here is a regular expression for matching phone numbers - 10 digit phone numbers. An explanation can be found here http://www.websina.com/bugzero/kb/regexp.html at bottom of the page.

re = /\(?\d{3}\)?([-\/\.])\d{3}\1\d{4}/;

This is a little more robust than previous expression in that parentheses and separators are optional and can be &quot;-&quot;, &quot;/&quot; or &quot;.&quot;</description>
		<content:encoded><![CDATA[<p>Hey Scripty,</p>
<p>Here is a regular expression for matching phone numbers &#8211; 10 digit phone numbers. An explanation can be found here <a href="http://www.websina.com/bugzero/kb/regexp.html" rel="nofollow">http://www.websina.com/bugzero/kb/regexp.html</a> at bottom of the page.</p>
<p>re = /\(?\d{3}\)?([-\/\.])\d{3}\1\d{4}/;</p>
<p>This is a little more robust than previous expression in that parentheses and separators are optional and can be &#034;-&#034;, &#034;/&#034; or &#034;.&#034;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew Woods</title>
		<link>http://www.scriptygoddess.com/archives/2008/05/03/phone-number-validation-with-jquery/comment-page-1/#comment-593682</link>
		<dc:creator>Andrew Woods</dc:creator>
		<pubDate>Mon, 01 Sep 2008 17:17:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/?p=1517#comment-593682</guid>
		<description>I needed to check for valid US phone numbers, so I wrote this function. HTH 


function validatePhoneNumber(phoneElement){
	
	if (isEmpty(phoneElement)){
		return false;
	}
	
	var regex = /^((\+?1-)?\d\d\d-)?\d\d\d-\d\d\d\d$/;
	console.log(&quot;phone=&quot; + phoneElement.value);

	if (phoneElement.value.match(regex)){
		return true;
	}
	return false;
}
</description>
		<content:encoded><![CDATA[<p>I needed to check for valid US phone numbers, so I wrote this function. HTH </p>
<p>function validatePhoneNumber(phoneElement){</p>
<p>	if (isEmpty(phoneElement)){<br />
		return false;<br />
	}</p>
<p>	var regex = /^((\+?1-)?\d\d\d-)?\d\d\d-\d\d\d\d$/;<br />
	console.log(&#034;phone=&#034; + phoneElement.value);</p>
<p>	if (phoneElement.value.match(regex)){<br />
		return true;<br />
	}<br />
	return false;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob</title>
		<link>http://www.scriptygoddess.com/archives/2008/05/03/phone-number-validation-with-jquery/comment-page-1/#comment-589999</link>
		<dc:creator>Rob</dc:creator>
		<pubDate>Tue, 12 Aug 2008 14:08:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/?p=1517#comment-589999</guid>
		<description>Thanks! Worked like a charm!</description>
		<content:encoded><![CDATA[<p>Thanks! Worked like a charm!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anand</title>
		<link>http://www.scriptygoddess.com/archives/2008/05/03/phone-number-validation-with-jquery/comment-page-1/#comment-588021</link>
		<dc:creator>Anand</dc:creator>
		<pubDate>Thu, 31 Jul 2008 20:59:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/?p=1517#comment-588021</guid>
		<description>Hey Scripty Goddess,

Can you write up a similar function to validate the US Zip codes by State?

If I have a drop-down containing all the states and then a text box for entering Zip, then my zip code should be validated according to the State selected above.

I tried using an Ajax callback to a Page Method and then checking the zip codes with State in the database, but its turning out to be too complicated.

Anand</description>
		<content:encoded><![CDATA[<p>Hey Scripty Goddess,</p>
<p>Can you write up a similar function to validate the US Zip codes by State?</p>
<p>If I have a drop-down containing all the states and then a text box for entering Zip, then my zip code should be validated according to the State selected above.</p>
<p>I tried using an Ajax callback to a Page Method and then checking the zip codes with State in the database, but its turning out to be too complicated.</p>
<p>Anand</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JT</title>
		<link>http://www.scriptygoddess.com/archives/2008/05/03/phone-number-validation-with-jquery/comment-page-1/#comment-582816</link>
		<dc:creator>JT</dc:creator>
		<pubDate>Fri, 04 Jul 2008 04:59:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/?p=1517#comment-582816</guid>
		<description>function isValidPhoneNumber(ph) {
    if (ph == null) {
        return false;
    }

    var stripped = ph.replace(/[\s()+-]&#124;ext\.?/gi, &quot;&quot;);

    // 10 is the minimum number of numbers required
    return ((/\d{10,}/i).test(stripped));
}

Literal regexes are surrounded by slash (/) characters, like quotes surround string literals. The syntax is /[regex]/[flags]. 

So, the first regex is [\s()+-]&#124;ext\.? which means: match either a whitespace, parenthesis, +, - OR the literal ext, optionally ending in a full-stop (period). When used with the replace function it removes the allowed characters from the string, leaving you with only numbers (if it&#039;s valid).

The next regex is \d{10,} which means match a string that consists of at least 10 digits, more is allowed. If there are less digits, it won&#039;t match. If alpha chars are present, it won&#039;t match. The number 10 is your minimum number of digits.

Note that in your solution the number 200txxxex200xxx200xxt.x2 is valid.

http://www.regular-expressions.info/ is a great regex resource, and the Mozilla JavaScript reference can be helpful too (http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference).

I hope this helps!</description>
		<content:encoded><![CDATA[<p>function isValidPhoneNumber(ph) {<br />
    if (ph == null) {<br />
        return false;<br />
    }</p>
<p>    var stripped = ph.replace(/[\s()+-]|ext\.?/gi, &#034;&#034;);</p>
<p>    // 10 is the minimum number of numbers required<br />
    return ((/\d{10,}/i).test(stripped));<br />
}</p>
<p>Literal regexes are surrounded by slash (/) characters, like quotes surround string literals. The syntax is /[regex]/[flags]. </p>
<p>So, the first regex is [\s()+-]|ext\.? which means: match either a whitespace, parenthesis, +, &#8211; OR the literal ext, optionally ending in a full-stop (period). When used with the replace function it removes the allowed characters from the string, leaving you with only numbers (if it&#039;s valid).</p>
<p>The next regex is \d{10,} which means match a string that consists of at least 10 digits, more is allowed. If there are less digits, it won&#039;t match. If alpha chars are present, it won&#039;t match. The number 10 is your minimum number of digits.</p>
<p>Note that in your solution the number 200txxxex200xxx200xxt.x2 is valid.</p>
<p><a href="http://www.regular-expressions.info/" rel="nofollow">http://www.regular-expressions.info/</a> is a great regex resource, and the Mozilla JavaScript reference can be helpful too (<a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference" rel="nofollow">http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference</a>).</p>
<p>I hope this helps!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jennifer</title>
		<link>http://www.scriptygoddess.com/archives/2008/05/03/phone-number-validation-with-jquery/comment-page-1/#comment-582805</link>
		<dc:creator>Jennifer</dc:creator>
		<pubDate>Fri, 04 Jul 2008 03:32:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/?p=1517#comment-582805</guid>
		<description>JT - if you can write the exact regex I can update the post. Unfortunately, regex is not something I&#039;ve ever been able to wrap my head around. I wish I knew it better - but it just completely stumps me.</description>
		<content:encoded><![CDATA[<p>JT &#8211; if you can write the exact regex I can update the post. Unfortunately, regex is not something I&#039;ve ever been able to wrap my head around. I wish I knew it better &#8211; but it just completely stumps me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JT</title>
		<link>http://www.scriptygoddess.com/archives/2008/05/03/phone-number-validation-with-jquery/comment-page-1/#comment-582780</link>
		<dc:creator>JT</dc:creator>
		<pubDate>Fri, 04 Jul 2008 01:21:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/?p=1517#comment-582780</guid>
		<description>I&#039;d suggest you could make this code a lot simpler by converting it to a regex - replace &#039;[()+ ]*&#124;ext\.&#039; with nothing, then match to &#039;[0-9]{1,}&#039;. This will remove the allowed characters then assert the numeric only and length conditions in 2 lines. 

This should be more performant, maintainable and readable than the current solution. Note I haven&#039;t tested the above regexes, but they&#039;d be close to the mark.</description>
		<content:encoded><![CDATA[<p>I&#039;d suggest you could make this code a lot simpler by converting it to a regex &#8211; replace &#039;[()+ ]*|ext\.&#039; with nothing, then match to &#039;[0-9]{1,}&#039;. This will remove the allowed characters then assert the numeric only and length conditions in 2 lines. </p>
<p>This should be more performant, maintainable and readable than the current solution. Note I haven&#039;t tested the above regexes, but they&#039;d be close to the mark.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob S</title>
		<link>http://www.scriptygoddess.com/archives/2008/05/03/phone-number-validation-with-jquery/comment-page-1/#comment-579577</link>
		<dc:creator>Bob S</dc:creator>
		<pubDate>Fri, 20 Jun 2008 07:45:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/?p=1517#comment-579577</guid>
		<description>I&#039;m pretty new to jQuery, too, but let me make one recommendation for your future sites:
&lt;script src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js&quot;&gt;&lt;/script&gt; (I don&#039;t know what your site will do w/ HTML in comments, so please bear with me).  Google is now hosting jQuery along with various other popular JavaScript frameworks at addresses such as the above.  The best description of this is at http://ajaxian.com/archives/announcing-ajax-libraries-api-speed-up-your-ajax-apps-with-googles-infrastructure .  For me, a very low-level developer, this means three things: 1) I never have to download jQuery again -- unless I&#039;m doing off-line development, which is pretty much never; 2) no load on my server for serving up the jQuery library; 3) with enough people using this, the odds are good that the user will already have downloaded the self-same file at the behest of another site using the same Google hosting, and will save a little time and bandwidth.</description>
		<content:encoded><![CDATA[<p>I&#039;m pretty new to jQuery, too, but let me make one recommendation for your future sites:<br />
&lt;script src=&#034;http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js&#034;&gt;&lt;/script&gt; (I don&#039;t know what your site will do w/ HTML in comments, so please bear with me).  Google is now hosting jQuery along with various other popular JavaScript frameworks at addresses such as the above.  The best description of this is at <a href="http://ajaxian.com/archives/announcing-ajax-libraries-api-speed-up-your-ajax-apps-with-googles-infrastructure" rel="nofollow">http://ajaxian.com/archives/announcing-ajax-libraries-api-speed-up-your-ajax-apps-with-googles-infrastructure</a> .  For me, a very low-level developer, this means three things: 1) I never have to download jQuery again &#8212; unless I&#039;m doing off-line development, which is pretty much never; 2) no load on my server for serving up the jQuery library; 3) with enough people using this, the odds are good that the user will already have downloaded the self-same file at the behest of another site using the same Google hosting, and will save a little time and bandwidth.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.259 seconds -->
