Flash Games
 FAQ   Search   Memberlist   Usergroups   Register  Profile   Log in to check your private messages   Log in 


Java validation help



 

Post new topic   Reply to topic  
   DEVPPL Forum Index -> JavaScript Forum
View previous topic :: View next topic  
Author Message
mikkel



Joined: 01 Mar 2007
Posts: 4
Location: London

PostPosted: Thu Mar 01, 2007 11:48 pm    Post subject: Java validation help Reply with quote

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>
Back to top
View user's profile Send private message
sachav



Joined: 03 Mar 2007
Posts: 32

PostPosted: Sat Mar 03, 2007 5:50 pm    Post subject: Re: Java validation help Reply with quote

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;
}
Back to top
View user's profile Send private message
mikkel



Joined: 01 Mar 2007
Posts: 4
Location: London

PostPosted: Sat Mar 03, 2007 6:08 pm    Post subject: Re: Java validation help Reply with quote

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>
Back to top
View user's profile Send private message
sachav



Joined: 03 Mar 2007
Posts: 32

PostPosted: Sat Mar 03, 2007 6:53 pm    Post subject: Re: Java validation help Reply with quote

Can you put it online so i can see it?
Back to top
View user's profile Send private message
mikkel



Joined: 01 Mar 2007
Posts: 4
Location: London

PostPosted: Sat Mar 03, 2007 7:58 pm    Post subject: Re: Java validation help Reply with quote

http://206.169.68.234/schedule/schedule_mammography_hbc3.html

Thanks
Back to top
View user's profile Send private message
sachav



Joined: 03 Mar 2007
Posts: 32

PostPosted: Sat Mar 03, 2007 8:00 pm    Post subject: Re: Java validation help Reply with quote

I don't see the problem...
Put a wrong DOB like 58469ffg and it'll tell you its wrong
Back to top
View user's profile Send private message
mikkel



Joined: 01 Mar 2007
Posts: 4
Location: London

PostPosted: Sat Mar 03, 2007 9:56 pm    Post subject: Re: Java validation help Reply with quote

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.
Back to top
View user's profile Send private message
sachav



Joined: 03 Mar 2007
Posts: 32

PostPosted: Sat Mar 03, 2007 10:55 pm    Post subject: Re: Java validation help Reply with quote

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
}
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    DEVPPL Forum Index -> JavaScript Forum All times are GMT + 1 Hour
Page 1 of 1

 
 
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:

 


Powered by phpBB © 2001, 2005 phpBB Group - Modified by DEVPPL

Flash Games - Sitemap