Flash Games

 FAQ   Search   Members   Groups   User Control Panel      Login 

It is currently Fri Jan 09, 2009 3:16 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Java validation help
PostPosted: Thu Mar 01, 2007 11:48 pm 
Offline

Joined: Thu Mar 01, 2007 11:45 pm
Posts: 4
Location: London
hi...I'm trying to validate phone number (correct format), name (only letters and minimun 2 letter) and DOB (Correct format, no letters). What I have so far only returns false in the user leaves the field "Empty". Any help would be greatly appreciated, thx!:

<script type="text/javascript">

<!--

function validate_form ( )
{
valid = true;

if ( document.schedule.firstname.value == "" )
{
alert ( "Please fill in your 'First Name'" );
valid = false;
}

else if ( document.schedule.lastname.value == "" )
{
alert ( "Please fill in your 'Last Name'" );
document.schedule.lastname.focus();
valid = false;
}

else if ( document.schedule.phone.value == "" )
{
alert ( "Please fill in your 'Phone Number' and remember to include your area code" );
document.schedule.phone.focus();
valid = false;
}

else if ( document.schedule.phone2.value == "" )
{
alert ( "Please fill in your 'Phone Number' and remember to include your area code" );
document.schedule.phone2.focus();
valid = false;
}

else if ( document.schedule.phone3.value == "" )
{
alert ( "Please fill in your 'Phone Number' and remember to include your area code" );
document.schedule.phone3.focus();
valid = false;
}

else if ( document.schedule.dob.value == "" )
{
alert ( "Please fill in your 'Date of Birth'. Your birth date must be in the past." );
document.schedule.dob.focus();
valid = false;
}

else if ( ( document.schedule.referral[0].checked == false ) && ( document.schedule.referral[1].checked == false ) )
{
alert ( "Do you have a referral from your doctor?" );
valid = false;
}

else if ( ( document.schedule.hmo[0].checked == false ) && ( document.schedule.hmo[1].checked == false ) )
{
alert ( "Is your insurance in an Health Maintenance Organization (HMO)?" );
valid = false;
}

else if ( ( document.schedule.hmo[0].checked == false ) && ( document.schedule.hmo[1].checked == true ) )
{
alert ( "HMO Insurance plans require an authorization. Please contact your MD to obtain this, and come back to our website to request your appointment." );
valid = false;
}


return valid;
}

//-->

</script>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 03, 2007 5:50 pm 
Offline

Joined: Sat Mar 03, 2007 4:40 pm
Posts: 32
Phone:
Code:
a = document.schedule.phone.value/2
if (isNaN(a))
{
alert ( "Wrong format for 'Phone'" );
valid = false;
}


Name:
Code:
b = document.schedule.name.value
d = b.length
c = document.schedule.name.value
for(i=0;i<d;i++)
{
if(c.charAt(i)=='0' || c.charAt(i)=='1' || c.charAt(i)=='2' || c.charAt(i)=='3' || c.charAt(i)=='4' || c.charAt(i)=='5' || c.charAt(i)=='6' || c.charAt(i)=='7' || c.charAt(i)=='8' || c.charAt(i)=='9' || c.charAt(i)==',' || c.charAt(i)==';' || c.charAt(i)=='=' || c.charAt(i)=='+' || c.charAt(i)=='-' || c.charAt(i)=='_' || c.charAt(i)=='!' || c.charAt(i)=='@' || c.charAt(i)=='#' || c.charAt(i)=='$' || c.charAt(i)=='%' || c.charAt(i)=='^' || c.charAt(i)=='&' || c.charAt(i)=='(' || c.charAt(i)=='*' || c.charAt(i)==')')
{
alert("Wrong format for 'Name'")
break
}
}


DOB:
Code:
g = document.schedule.dob.value/2
if (isNaN(g))
{
alert ( "Wrong format for 'DOB'" );
valid = false;
}


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 03, 2007 6:08 pm 
Offline

Joined: Thu Mar 01, 2007 11:45 pm
Posts: 4
Location: London
Thanks for your help! I pasted the DOB java code into the beginning of my script but nothing happens? What am I doing wrong?

<script type="text/javascript">

<!--

function validate_form ( )
{
valid = true;


g = document.schedule.dob.value/2

if (isNaN(g))
{
alert ( "Wrong format for 'DOB'" );
valid = false;
}


if ( document.schedule.firstname.value == "" )
{
alert ( "Please fill in your 'First Name'" );
valid = false;
}

else if ( document.schedule.lastname.value == "" )
{
alert ( "Please fill in your 'Last Name'" );
document.schedule.lastname.focus();
valid = false;
}

else if ( document.schedule.phone.value == "" )
{
alert ( "Please fill in your 'Phone Number' and remember to include your area code" );
document.schedule.phone.focus();
valid = false;
}

else if ( document.schedule.phone2.value == "" )
{
alert ( "Please fill in your 'Phone Number' and remember to include your area code" );
document.schedule.phone2.focus();
valid = false;
}

else if ( document.schedule.phone3.value == "" )
{
alert ( "Please fill in your 'Phone Number' and remember to include your area code" );
document.schedule.phone3.focus();
valid = false;
}

else if ( document.schedule.dob.value == "" )
{
alert ( "Please fill in your 'Date of Birth'. Your birth date must be in the past." );
document.schedule.dob.focus();
valid = false;
}

else if ( ( document.schedule.referral[0].checked == false ) && ( document.schedule.referral[1].checked == false ) )
{
alert ( "Do you have a referral from your doctor?" );
valid = false;
}

else if ( ( document.schedule.hmo[0].checked == false ) && ( document.schedule.hmo[1].checked == false ) )
{
alert ( "Is your insurance in an Health Maintenance Organization (HMO)?" );
valid = false;
}

else if ( ( document.schedule.hmo[0].checked == false ) && ( document.schedule.hmo[1].checked == true ) )
{
alert ( "HMO Insurance plans require an authorization. Please contact your MD to obtain this, and come back to our website to request your appointment." );
valid = false;
}


return valid;
}

//-->

</script>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 03, 2007 6:53 pm 
Offline

Joined: Sat Mar 03, 2007 4:40 pm
Posts: 32
Can you put it online so i can see it?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 03, 2007 7:58 pm 
Offline

Joined: Thu Mar 01, 2007 11:45 pm
Posts: 4
Location: London
http://206.169.68.234/schedule/schedule ... _hbc3.html

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 03, 2007 8:00 pm 
Offline

Joined: Sat Mar 03, 2007 4:40 pm
Posts: 32
I don't see the problem...
Put a wrong DOB like 58469ffg and it'll tell you its wrong


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 03, 2007 9:56 pm 
Offline

Joined: Thu Mar 01, 2007 11:45 pm
Posts: 4
Location: London
But if you just put "1" or 58469ffg or it continues.

And 12/02/1943 is not accepted?

Thanks for all your help...I know I have a lot to learn before all this makes sense.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 03, 2007 10:55 pm 
Offline

Joined: Sat Mar 03, 2007 4:40 pm
Posts: 32
Sorry, I thought you meant like 'all numbers':
Replace the whole DOB script by:
Code:
a = document.schedule.dob.value
b = a.replace(/\//g,"")
c = b*2
if(a.length!=10 && a.length!=8)
{
alert('Please put the DOB in the correct format.')
valid = false
}
else
{
if(isNaN(c))
{
alert('Please put the DOB in the correct format.')
valid = false
}
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group - Flash Games - TNX Invitation Code - TNX Review

Welcome to DEVPPL.com
You are not logged in, which means that you can't post in the forums.
Click here to Register

If you are a current member here on DEVPPL, please login below:

User:
Pass:
Log me on automatically each visit: