<?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: Javascript Validation</title>
	<atom:link href="http://www.scriptygoddess.com/archives/2003/02/09/javascript-validation/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scriptygoddess.com/archives/2003/02/09/javascript-validation/</link>
	<description></description>
	<pubDate>Mon, 08 Sep 2008 15:38:13 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Jennifer</title>
		<link>http://www.scriptygoddess.com/archives/2003/02/09/javascript-validation/#comment-9036</link>
		<dc:creator>Jennifer</dc:creator>
		<pubDate>Tue, 16 Dec 2003 18:43:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/archives/2003/02/09/javascript-validation/#comment-9036</guid>
		<description>Another note to myself: I made another variation to the function above:

&lt;code&gt;function validRequired(formField,fieldLabel,alertmsg)
{
var result = true;
if (formField.value == "")
{
if (alertmsg == "") {
alert('Please enter your ' + fieldLabel +'.');
} else {
alert(alertmsg);
}
formField.focus();
result = false;
}
return result;
}&lt;/code&gt;

And then it's called like this:
for using the "default" alert message:

&lt;code&gt;if (!validRequired(formname.name,"name","")) {
return false;
}&lt;/code&gt;

or this way to put in a "custom" alert message:

&lt;code&gt;if (!validRequired(formname.iLikePie,"","Please type in yes or no or whatever you want.")) {
return false;
}&lt;/code&gt;
</description>
		<content:encoded><![CDATA[<p>Another note to myself: I made another variation to the function above:</p>
<p><code>function validRequired(formField,fieldLabel,alertmsg)<br />
{<br />
var result = true;<br />
if (formField.value == "")<br />
{<br />
if (alertmsg == "") {<br />
alert('Please enter your ' + fieldLabel +'.');<br />
} else {<br />
alert(alertmsg);<br />
}<br />
formField.focus();<br />
result = false;<br />
}<br />
return result;<br />
}</code></p>
<p>And then it&#8217;s called like this:<br />
for using the &#8220;default&#8221; alert message:</p>
<p><code>if (!validRequired(formname.name,"name","")) {<br />
return false;<br />
}</code></p>
<p>or this way to put in a &#8220;custom&#8221; alert message:</p>
<p><code>if (!validRequired(formname.iLikePie,"","Please type in yes or no or whatever you want.")) {<br />
return false;<br />
}</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jennifer</title>
		<link>http://www.scriptygoddess.com/archives/2003/02/09/javascript-validation/#comment-9032</link>
		<dc:creator>Jennifer</dc:creator>
		<pubDate>Tue, 11 Feb 2003 03:52:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/archives/2003/02/09/javascript-validation/#comment-9032</guid>
		<description>Ok. Here's a better email validation function that I found &lt;a href="http://www.smartwebby.com/DHTML/email_validation.asp" target="_blank" rel="nofollow"&gt;here&lt;/a&gt; and it seems to accept the .name and .info etc. (but it's not pretty!) ;-)

&lt;code&gt;&#60;script language = "Javascript"&#62;
/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
function echeck(str) {
var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(at)==-1 &#124;&#124; str.indexOf(at)==0 &#124;&#124; str.indexOf(at)==lstr){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(dot)==-1 &#124;&#124; str.indexOf(dot)==0 &#124;&#124; str.indexOf(dot)==lstr){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(at,(lat+1))!=-1){
alert("Invalid E-mail ID")
return false
}
if (str.substring(lat-1,lat)==dot &#124;&#124; str.substring(lat+1,lat+2)==dot){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(dot,(lat+2))==-1){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(" ")!=-1){
alert("Invalid E-mail ID")
return false
}
return true
}
&#60;/script&#62;&lt;/code&gt;

So they're display of the validation function looks like this:

&lt;code&gt;function ValidateForm(){
var emailID=document.frmSample.txtEmail&lt;br&gt;
if ((emailID.value==null)&#124;&#124;(emailID.value=="")){
alert("Please Enter your Email ID")
emailID.focus()
return false
}
if (echeck(emailID.value)==false){
emailID.value=""
emailID.focus()
return false
}
return true
 }&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Ok. Here&#8217;s a better email validation function that I found <a href="http://www.smartwebby.com/DHTML/email_validation.asp" target="_blank" rel="nofollow">here</a> and it seems to accept the .name and .info etc. (but it&#8217;s not pretty!) <img src='http://www.scriptygoddess.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><code>&lt;script language = "Javascript"&gt;<br />
/**<br />
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)<br />
 */<br />
function echeck(str) {<br />
var at="@"<br />
var dot="."<br />
var lat=str.indexOf(at)<br />
var lstr=str.length<br />
var ldot=str.indexOf(dot)<br />
if (str.indexOf(at)==-1){<br />
alert("Invalid E-mail ID")<br />
return false<br />
}<br />
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){<br />
alert("Invalid E-mail ID")<br />
return false<br />
}<br />
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){<br />
alert("Invalid E-mail ID")<br />
return false<br />
}<br />
if (str.indexOf(at,(lat+1))!=-1){<br />
alert("Invalid E-mail ID")<br />
return false<br />
}<br />
if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){<br />
alert("Invalid E-mail ID")<br />
return false<br />
}<br />
if (str.indexOf(dot,(lat+2))==-1){<br />
alert("Invalid E-mail ID")<br />
return false<br />
}<br />
if (str.indexOf(" ")!=-1){<br />
alert("Invalid E-mail ID")<br />
return false<br />
}<br />
return true<br />
}<br />
&lt;/script&gt;</code></p>
<p>So they&#8217;re display of the validation function looks like this:</p>
<p><code>function ValidateForm(){<br />
var emailID=document.frmSample.txtEmail<br />
if ((emailID.value==null)||(emailID.value==&#8221;")){<br />
alert(&#8221;Please Enter your Email ID&#8221;)<br />
emailID.focus()<br />
return false<br />
}<br />
if (echeck(emailID.value)==false){<br />
emailID.value=&#8221;"<br />
emailID.focus()<br />
return false<br />
}<br />
return true<br />
 }</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://www.scriptygoddess.com/archives/2003/02/09/javascript-validation/#comment-9035</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/archives/2003/02/09/javascript-validation/#comment-9035</guid>
		<description>Im trying to create a code using java script on a button, so when clicked it will check the current pages address and will take answer and depending on that will send it to one of two links 
there are two address outcomes that the original search should come up with and two links it can go to. IM stumped on where to begin with this and how to get it to look at the web address. 
any help would be greatly appreciated
Thanks
chinkley@hotmail.com</description>
		<content:encoded><![CDATA[<p>Im trying to create a code using java script on a button, so when clicked it will check the current pages address and will take answer and depending on that will send it to one of two links<br />
there are two address outcomes that the original search should come up with and two links it can go to. IM stumped on where to begin with this and how to get it to look at the web address.<br />
any help would be greatly appreciated<br />
Thanks<br />
<a href="mailto:chinkley@hotmail.com">chinkley@hotmail.com</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jennifer</title>
		<link>http://www.scriptygoddess.com/archives/2003/02/09/javascript-validation/#comment-9034</link>
		<dc:creator>Jennifer</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/archives/2003/02/09/javascript-validation/#comment-9034</guid>
		<description>One more addition - to simplify the checking of many fields to see that they're not empty, add the function:&lt;h3&gt;function validRequired(formField,fieldLabel) {
var result = true;
if (formField.value == "") {
alert('Please enter your ' + fieldLabel +'.');
formField.focus();
result = false;
}
return result;
}&lt;/h3&gt;&lt;p&gt;Then in the main validate function do this for each field you're checking:&lt;h3&gt;if (!validRequired(formname.first_name,"first name")) {
return false;
}&lt;/h3&gt;&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>One more addition - to simplify the checking of many fields to see that they&#8217;re not empty, add the function:<br />
<h3>function validRequired(formField,fieldLabel) {<br />
var result = true;<br />
if (formField.value == &#8220;&#8221;) {<br />
alert(&#8217;Please enter your &#8216; + fieldLabel +&#8217;.');<br />
formField.focus();<br />
result = false;<br />
}<br />
return result;<br />
}</h3>
<p>Then in the main validate function do this for each field you&#8217;re checking:<br />
<h3>if (!validRequired(formname.first_name,&#8221;first name&#8221;)) {<br />
return false;<br />
}</h3></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jennifer</title>
		<link>http://www.scriptygoddess.com/archives/2003/02/09/javascript-validation/#comment-9033</link>
		<dc:creator>Jennifer</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/archives/2003/02/09/javascript-validation/#comment-9033</guid>
		<description>One more validation here: I had a list of radio buttons - which it wasn't "required" to select one - but if you DID select a paricular one - then there was a sub list that WAS required.

For example:
How will you be arriving?
(_) car
(_) boat
(_) airplane
(_) flight 001
(_) flight 002

If you select "airplne" then you have to select which flight...

Here's the code that will validate the form is filled out correctly:

&lt;b&gt;var airplaneChecked = false;
var flightChecked = false;
for (i=0; i&#60;document.formName.transport.length; i++) {
			if (document.formName.transport[i].checked &#038;&#038; document.formName.transport[i].value == "airplane") {
airplaneChecked = true;
}
}
if (airplaneChecked) { 
for (i=0; i&#60;document.formName.flight.length; i++) {
if (document.formName.flight[i].checked) {
flightChecked = true;
}
}		
}
if (!flightChecked &#038;&#038; airplaneChecked) { 
window.alert("Please select a flight.");
document.formName.flight[0].focus()
return false;
}&lt;/b&gt;</description>
		<content:encoded><![CDATA[<p>One more validation here: I had a list of radio buttons - which it wasn&#8217;t &#8220;required&#8221; to select one - but if you DID select a paricular one - then there was a sub list that WAS required.</p>
<p>For example:<br />
How will you be arriving?<br />
(_) car<br />
(_) boat<br />
(_) airplane<br />
(_) flight 001<br />
(_) flight 002</p>
<p>If you select &#8220;airplne&#8221; then you have to select which flight&#8230;</p>
<p>Here&#8217;s the code that will validate the form is filled out correctly:</p>
<p><b>var airplaneChecked = false;<br />
var flightChecked = false;<br />
for (i=0; i&lt;document.formName.transport.length; i++) {<br />
			if (document.formName.transport[i].checked &#038;&#038; document.formName.transport[i].value == &#8220;airplane&#8221;) {<br />
airplaneChecked = true;<br />
}<br />
}<br />
if (airplaneChecked) {<br />
for (i=0; i&lt;document.formName.flight.length; i++) {<br />
if (document.formName.flight[i].checked) {<br />
flightChecked = true;<br />
}<br />
}<br />
}<br />
if (!flightChecked &#038;&#038; airplaneChecked) {<br />
window.alert(&#8221;Please select a flight.&#8221;);<br />
document.formName.flight[0].focus()<br />
return false;<br />
}</b></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jester</title>
		<link>http://www.scriptygoddess.com/archives/2003/02/09/javascript-validation/#comment-9031</link>
		<dc:creator>Jester</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/archives/2003/02/09/javascript-validation/#comment-9031</guid>
		<description>&lt;p&gt;The idea is to save resources, as Jen said, but javascript can easily be turned off so you &lt;em&gt;must&lt;/em&gt; re-do the checks with PHP to make sure they don't get through. 99% of users (apparently) run with javascript enabled anyways, you just need to stop the idiots from trying to mess with your forms and such. Without proper checks users can manipulate file functions or inject into SQL queries (SQL injection vulnerabilites are a common newbie error).&lt;/p&gt;
&lt;p&gt;Javascript is the quick solution but always back the filters up with something that can't be disabled.&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>The idea is to save resources, as Jen said, but javascript can easily be turned off so you <em>must</em> re-do the checks with PHP to make sure they don&#8217;t get through. 99% of users (apparently) run with javascript enabled anyways, you just need to stop the idiots from trying to mess with your forms and such. Without proper checks users can manipulate file functions or inject into SQL queries (SQL injection vulnerabilites are a common newbie error).</p>
<p>Javascript is the quick solution but always back the filters up with something that can&#8217;t be disabled.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jennifer</title>
		<link>http://www.scriptygoddess.com/archives/2003/02/09/javascript-validation/#comment-9030</link>
		<dc:creator>Jennifer</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/archives/2003/02/09/javascript-validation/#comment-9030</guid>
		<description>Ok, I can see making it so that it will take .info or .museum (are those even "available" yet? I thought it was still in discussion) (also, what should that line be so that it would allow those?)

...but "+"? Is that even an allowed character for email? I didn't think it was...</description>
		<content:encoded><![CDATA[<p>Ok, I can see making it so that it will take .info or .museum (are those even &#8220;available&#8221; yet? I thought it was still in discussion) (also, what should that line be so that it would allow those?)</p>
<p>&#8230;but &#8220;+&#8221;? Is that even an allowed character for email? I didn&#8217;t think it was&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jim Ley</title>
		<link>http://www.scriptygoddess.com/archives/2003/02/09/javascript-validation/#comment-9029</link>
		<dc:creator>Jim Ley</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/archives/2003/02/09/javascript-validation/#comment-9029</guid>
		<description>Don't over-validate !!

And make sure you don't validate incorrectly...

Your email:
if (!(/^&#92;w+([&#92;.-]?&#92;w+)*@&#92;w+([&#92;.-]?&#92;w+)*(&#92;.&#92;w{2,3})+&#36;/.test

Which appears to disallow + in the part before the @ and only allows @a.b.cc or @a.b.ccc and not @a.info or @a.b.c.d.e.f.g.h.museum or ...

Over validating scares people away who might otherwise have spent some money or whatever...</description>
		<content:encoded><![CDATA[<p>Don&#8217;t over-validate !!</p>
<p>And make sure you don&#8217;t validate incorrectly&#8230;</p>
<p>Your email:<br />
if (!(/^&#92;w+([&#92;.-]?&#92;w+)*@&#92;w+([&#92;.-]?&#92;w+)*(&#92;.&#92;w{2,3})+&#36;/.test</p>
<p>Which appears to disallow + in the part before the @ and only allows @a.b.cc or @a.b.ccc and not @a.info or @a.b.c.d.e.f.g.h.museum or &#8230;</p>
<p>Over validating scares people away who might otherwise have spent some money or whatever&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jennifer</title>
		<link>http://www.scriptygoddess.com/archives/2003/02/09/javascript-validation/#comment-9028</link>
		<dc:creator>Jennifer</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/archives/2003/02/09/javascript-validation/#comment-9028</guid>
		<description>They're not contradictory, but maybe my point outside the parens was misunderstood. Here's a scenario:

Lazy form filler tries to fill out just one field where all fields are required - javascript catches each one and tells him "Sorry, dude - gotta fill out that field" "yup, AND that field" "YES! And that field too!!" - If you ONLY have server-side checking - then that's three trips to the server. Three trips to the server when it was possible to catch it with javascript - that is what I mean by a "waste of server resources".

My point in the beginning was check it with javascript then once again when the stuff gets to the server. (Not mentioned: in case (1) malicious stuff you talk about and/or (2) javascript turned off). "double"-checking the form data once on the server - that is NOT a waste of server resources.

Is that clearer?</description>
		<content:encoded><![CDATA[<p>They&#8217;re not contradictory, but maybe my point outside the parens was misunderstood. Here&#8217;s a scenario:</p>
<p>Lazy form filler tries to fill out just one field where all fields are required - javascript catches each one and tells him &#8220;Sorry, dude - gotta fill out that field&#8221; &#8220;yup, AND that field&#8221; &#8220;YES! And that field too!!&#8221; - If you ONLY have server-side checking - then that&#8217;s three trips to the server. Three trips to the server when it was possible to catch it with javascript - that is what I mean by a &#8220;waste of server resources&#8221;.</p>
<p>My point in the beginning was check it with javascript then once again when the stuff gets to the server. (Not mentioned: in case (1) malicious stuff you talk about and/or (2) javascript turned off). &#8220;double&#8221;-checking the form data once on the server - that is NOT a waste of server resources.</p>
<p>Is that clearer?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arve Bersvendsen</title>
		<link>http://www.scriptygoddess.com/archives/2003/02/09/javascript-validation/#comment-9027</link>
		<dc:creator>Arve Bersvendsen</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/archives/2003/02/09/javascript-validation/#comment-9027</guid>
		<description>No claws.   :-)

My point was(is) that the statement inside the paranthesis and the statement outside are (logically) contradictory.

And, at least from what I see from novice/intermediate web authors, they would interpret the combination of these two statements as "it's mostly ok to ignore server-side checking". I've seen this happen a number of times in newsgroup I frequent, and it's hard to explain to people why.

But I felt that it had to be clearified. I apologize for any scratchmark you unintentionally got from my claws.</description>
		<content:encoded><![CDATA[<p>No claws.   <img src='http://www.scriptygoddess.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
My point was(is) that the statement inside the paranthesis and the statement outside are (logically) contradictory.</p>
<p>And, at least from what I see from novice/intermediate web authors, they would interpret the combination of these two statements as &#8220;it&#8217;s mostly ok to ignore server-side checking&#8221;. I&#8217;ve seen this happen a number of times in newsgroup I frequent, and it&#8217;s hard to explain to people why.</p>
<p>But I felt that it had to be clearified. I apologize for any scratchmark you unintentionally got from my claws.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

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