JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 20th, 2012, 01:12 AM
thesocialmedium thesocialmedium is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 2 thesocialmedium User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 27 sec
Reputation Power: 0
Nesting issue while duplicating functions

Greetings,

I have a functioning javascript file here that checks to make sure all the values in a form are filled out. It also checks to make sure that the email address is in a valid format.

Code:
function regchk()
	{	
	  frm=document.myform;
	  
		 if(frm.fname.value=="")
		{
		alert("Please enter your first and last name");
		frm.fname.focus();
		return false;
		}
		 if(frm.lname.value=="")
		{
		alert("Please enter your first and last name");
		frm.lname.focus();
		return false;
		}
		
		if(frm.em.value=="")
		{
		alert("Please enter your email address");
		frm.em.focus();
		return false;
		}
		else
		{
			if(!emailInvalid(frm.em.value))
			{
				alert("Please enter a valid email address");
				frm.em.focus();
				return false;
			}
		}
		
		if(frm.ptcity.value=="")
		{
		alert("Please enter your city");
		frm.ptcity.focus();
		return false;
		}
		
		if(frm.st.value=="")
		{
		alert("Please enter your state");
		frm.st.focus();
		return false;
		}
		
		if(frm.zip.value=="")
		{
		alert("Please enter your zip code");
		frm.zip.focus();
		return false;
		}
		
		if(frm.pn.value=="")
		{
		alert("Please enter your phone number");
		frm.pn.focus();
		return false;
		}
 		
	if ( frm.agree.checked == false ) 
		{ 
		alert ( "You must agree to the Terms and Conditions and Privacy Policy to continue" ); 
		return false; 
		}
	}
	function emailInvalid(s)
{
	if(!(s.match(/^[\w]+([_|\.-][\w]{1,})*@[\w]{2,}([_|\.-][\w]{1,})*\.([a-z]{2,4})$/i) ))
        {
		return false;
		
	}
	else
		return true;
} 




I'd like to now modify it to also ensure that the phone number is 10 digits. I have been trying to use the following bit of code.

Code:
if(!phoneInvalid(frm.em.value))
			{
				alert("Please enter 10 digits for the phone number");
				frm.pn.focus();
				return false;
			}



	function phoneInvalid(s)
{
	if(phone.length != 10) { 
   alert("please enter 10 digits for the phone number");
        {
		return false;	
	}


However, I can't seem to properly nest the code to make the entire script function. I have been placing it wrong.


Can anyone please modify the original code above to ensure the phone number field is a valid 10 digits?

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Nesting issue while duplicating functions

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap