| View previous topic :: View next topic |
| Author |
Message |
mikkel
Joined: 01 Mar 2007 Posts: 4 Location: London
|
Posted: Thu Mar 01, 2007 11:48 pm Post subject: Java validation help |
|
|
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 |
|
 |
|
|
sachav
Joined: 03 Mar 2007 Posts: 32
|
Posted: Sat Mar 03, 2007 5:50 pm Post subject: Re: Java validation help |
|
|
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 |
|
 |
mikkel
Joined: 01 Mar 2007 Posts: 4 Location: London
|
Posted: Sat Mar 03, 2007 6:08 pm Post subject: Re: Java validation help |
|
|
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 |
|
 |
sachav
Joined: 03 Mar 2007 Posts: 32
|
Posted: Sat Mar 03, 2007 6:53 pm Post subject: Re: Java validation help |
|
|
| Can you put it online so i can see it? |
|
| Back to top |
|
 |
mikkel
Joined: 01 Mar 2007 Posts: 4 Location: London
|
|
| Back to top |
|
 |
sachav
Joined: 03 Mar 2007 Posts: 32
|
Posted: Sat Mar 03, 2007 8:00 pm Post subject: Re: Java validation help |
|
|
I don't see the problem...
Put a wrong DOB like 58469ffg and it'll tell you its wrong |
|
| Back to top |
|
 |
mikkel
Joined: 01 Mar 2007 Posts: 4 Location: London
|
Posted: Sat Mar 03, 2007 9:56 pm Post subject: Re: Java validation help |
|
|
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 |
|
 |
sachav
Joined: 03 Mar 2007 Posts: 32
|
Posted: Sat Mar 03, 2007 10:55 pm Post subject: Re: Java validation help |
|
|
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 |
|
 |
|