|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
|
|
#1
|
|||
|
|||
|
Javascript, a little php and form validation
Hello...
I am having difficulties, I can get the email validation to work for that field, but when I try and get the form validation to include the email validation, it won't work... Help someone!!! Before i throw the PC out the window. <SCRIPT LANGUAGE="JavaScript"> //This is the email validation: function validate_email(field) { var email = new String(field) var index=email.indexOf("@"); if(index>0) { var pindex=email.indexOf(".",index); if ((pindex>index+1) && (email.length>pindex+1)) return true; } alert("Enter valid email"); field.focus(); field.select(); return false; } //this is the form validation function validate(form) { var submitform = true; var manfields = "The following fields are Mandatory;nn"; if (form.username.value == '') { submitform = false; manfields += "Usernamen"; } if (form.email.value == '') { submitform = false; manfields += "Usernamen"; } if (submitform == false) { alert(manfields); return false; } } </SCRIPT> /*THis is the table that appears with the different fields users input, i have taken off most fields and just included username and email here, when not filled in the user can not submit this page until there is something there */ echo "<FORM NAME="u_form" METHOD="POST" ACTION="$PHP_SELF" onSubmit="return validate(this);"> echo "<INPUT TYPE="hidden" NAME="username" VALUE="$username">n"; echo "<INPUT NAME="email" TYPE="text" VALUE="$email" onChange="trim(this);validate_email(this)">n"; /* the text boxes work, it has been since i added a seperate function to validate the email that I can not get it to work. However the validation does work for the email, just will not work when I try and get it to stop the submision of the form. I have tried adding to the validate form function a check that see's if the validate email passed true or false... it will alert the user to correct the email, but will still allow the user to submit the form even though email is wrong.... help!! if more information is needed i can add it! */ |
|
#2
|
|||||
|
|||||
|
RE: Javascript, a little php and form validation
Try this, and forget about the email validation function you have now:
php Code:
(I put it in PHP tags, but it is javascript offcourse) |
|
#3
|
|||
|
|||
|
RE: Javascript, a little php and form validation
It works!!
But i had to do it a little different, with the pattern as it's own variable and the match being == null to alert the user of invalid email. But it works... and so much easier then what i was attempting. Thank you! |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Client Side Things > Javascript, a little php and form validation |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|