[solved] email form validation script

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
jyhm
Forum Contributor
Posts: 228
Joined: Tue Dec 19, 2006 10:08 pm
Location: Connecticut, USA
Contact:

[solved] email form validation script

Post by jyhm »

Can anyone tell the difference between these two scripts? They are simple validation scripts for an email form. It is called via the form action

Code: Select all

<form name="myform" action="testjscript.htm" method="post" onSubmit="return CheckData(this)">
They look completely identical to me, but only the first one works. This is driving me nuts! :evil:

Code: Select all

<script type="text/javascript" language="JavaScript">
				<!--
				/* This one works. */
				re = /[\<\>@#\$%\^\&\+=\{\}\[\]\|\\/]/;
				
			function CheckData(myform)	{
					
					if (myform.name.value == "")	{
						alert("Please Enter Your Name.");
						myform.name.focus();
						myform.name.select();
						var problem = true;
					}
					
					if (myform.email.value == "")	{
						alert("Please Enter Your Email.");
						myform.email.focus();
						myform.email.select();
						var problem = true;
					}
					
					if (myform.message.value == "")	{
						alert("Please Enter a Message.");
						myform.message.focus();
						myform.message.select();
						var problem = true;
					}

					if	(re.test(myform.message.value))	{
					 	alert("These symbols are not allowed: @ # $ % ^ & + = { } [ ] | \ / < >");
					 	myform.message.focus();
					 	myform.message.select();
					 	var problem = true;
					 	
					}
					
					if (problem==true)	{
						return false;
					} else	{
						return true;
					}
					
				}
		//-->
		</script>

Code: Select all

<script type="text/javascript" language="JavaScript">
				<!--
				/* This one does not work. */
				re = /[\<\>@#\$%\^\&\+=\{\}\[\]\|\\/]/;
				
			function CheckData(myform)	{
					
					
					if (myform.name.value == "")	{
						alert("Please Enter Your Name.");
						myform.name.focus();
						myform.name.select();
						var problem = true;
					}
					
					if (myform.email.value == "")	{
						alert("Please Enter Your Email.");
						myform.email.focus();
						myform.email.select();
						var problem = true;
						
					
					
					if (myform.message.value == "")	{
						alert("Please Enter a Message.");
						myform.message.focus();
						myform.message.select();
						var problem = true;
					}

					if	(re.test(myform.message.value))	{
					 	alert("These symbols are not allowed: @ # $ % ^ & + = { } [ ] | \ / < >");
					 	myform.message.focus();
					 	myform.message.select();
					 	var problem = true;
					 	
					}
					
					if (problem==true)	{
						return false;
					} else	{
						return true;
					}
					
				}
		//-->
		</script>
User avatar
jyhm
Forum Contributor
Posts: 228
Joined: Tue Dec 19, 2006 10:08 pm
Location: Connecticut, USA
Contact:

Post by jyhm »

Alas! I forgot a:

Code: Select all

'}'
at

Code: Select all

if (myform.email.value == "")   {
 alert("Please Enter Your Email.");
 myform.email.focus();
myform.email.select();
var problem = true;
It must look different when I post it because I could not find it on my editor.
Thanks for all your help guys! :D
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

glad I could help
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

You go NSG!
Post Reply