Asked By
Crispin
0 points
N/A
Posted on - 08/29/2011
Hi everybody!
I am a PHP web developer. I get some troubles using regular expressions for the form validation. It submits the form without validating the it.
The form contains the following fields 1) Name, 2) Address, 3) City, 4) State, 5) Country, 6) Email_ID, 7) Contact No., 8) Order. In that fields, except Address, State remaining fields are mandatory. We have to validate all these fields using JavaScript regular expressions. I cant find the error in the script I made. Please help me, I also attached the script here and inserted the image of the form for your reference.
Answered By
Josephm
0 points
N/A
#118718
Form submitted without being validated by the JavaScript regular expressions
Hello there,
The first problem I noticed is that you don't need so many functions to validate the page at all. I am providing you a sample form page and script which you can test and then modify for use according to your need. And it will work fine.
Â
Paste this code in a sample HTML file and then save it and open on the browser to see the effects. Copy complete code and make sure that you are using a blank HTML file to paste this code, since it has headers and everything.
Check the JavaScript use, it is working by using the "name" field of input tags.
And the errors are shown using JavaScript using Nested If Statements.
I hope it will function perfectly for you too, if you still face a problem making it on your own, I will write one for you.
Regards
Answered By
brod fl
0 points
N/A
#118719
Form submitted without being validated by the JavaScript regular expressions
Validation with java script is remains perfect concept and coding. Here I am giving an example in my style. You have to use it in your own style.
1.      Required fields:
function validateForm()
{
var x=document.forms["myForm"]["fname"].value;
if (x==null || x=="")
 {
 alert("First name must be filled out");
 return false;
 }
}
2.      Email validation:
function validateForm()
{
var x=document.forms["myForm"]["email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
 {
 alert("Not a valid e-mail address");
 return false;
 }
}