<?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"
	>
<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>
	<pubDate>Fri, 21 Nov 2008 19:40:26 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: brindle</title>
		<link>http://www.scriptygoddess.com/archives/2008/05/03/phone-number-validation-with-jquery/#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 "-", "/" or "."</description>
		<content:encoded><![CDATA[<p>Hey Scripty,</p>
<p>Here is a regular expression for matching phone numbers - 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-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("phone=" + 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-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-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-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, "");

    // 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'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't match. If alpha chars are present, it won'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, +, - 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 (http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference).</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-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'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 - 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.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JT</title>
		<link>http://www.scriptygoddess.com/archives/2008/05/03/phone-number-validation-with-jquery/#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'd suggest you could make this code a lot simpler by converting it to a regex - replace '[()+ ]*&#124;ext\.' with nothing, then match to '[0-9]{1,}'. 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't tested the above regexes, but they'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 - 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-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'm pretty new to jQuery, too, but let me make one recommendation for your future sites:
&#60;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js"&#62;&#60;/script&#62; (I don'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'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>
	<item>
		<title>By: spin</title>
		<link>http://www.scriptygoddess.com/archives/2008/05/03/phone-number-validation-with-jquery/#comment-574975</link>
		<dc:creator>spin</dc:creator>
		<pubDate>Fri, 23 May 2008 13:28:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/?p=1517#comment-574975</guid>
		<description>thanks for this. Saved me lots of time and hassle</description>
		<content:encoded><![CDATA[<p>thanks for this. Saved me lots of time and hassle</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: links for 2008-05-05 &#124; iKeif</title>
		<link>http://www.scriptygoddess.com/archives/2008/05/03/phone-number-validation-with-jquery/#comment-571315</link>
		<dc:creator>links for 2008-05-05 &#124; iKeif</dc:creator>
		<pubDate>Mon, 05 May 2008 17:36:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/?p=1517#comment-571315</guid>
		<description>[...] I've used before - and it's handy to have it cross library!cache javascript jquery js loader scriptygoddess » Blog Archive » Phone number validation with jquery 14 hours agojQuery phone number validation. Adding it to the pile.javascript jquery js validation [...]</description>
		<content:encoded><![CDATA[<p>[...] I&#039;ve used before - and it&#039;s handy to have it cross library!cache javascript jquery js loader scriptygoddess » Blog Archive » Phone number validation with jquery 14 hours agojQuery phone number validation. Adding it to the pile.javascript jquery js validation [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

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