Not Checking Validation

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Post Reply
Sunny
New php-forum User
New php-forum User
Posts: 23
Joined: Wed Nov 30, 2011 6:51 am

Not Checking Validation

Post by Sunny » Wed Oct 30, 2013 3:00 am

Hi

Form is not checking for Valid Values in Name & Email . What i feel is it is not going in Javascript Code.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Registration Form</title>
<link href="style/style.css" rel="stylesheet" type="text/css" media="all" />
<script type="text/javascript" src="js/script.js" > </script>
</head>

<body onload="document.registration.fname.focus();">
<div id="wrap">
<div id="wrap2">
<h2 class="free_account">Registeration Form</h2>
<form action="process.php" name="registration" onsubmit='return formValidation()' method="post" id="register_form">
<p class="validate_msg">Please fix the errors below!</p>
<p> <label for="name">First Name</label> <input name="fname" type="text" /> <span class="val_fname"></span> </p>
<p> <label for="email">Your Email</label> <input name="email" type="text" /> <span class="val_email"></span> </p>

<input type="submit" name="submit" value="Register">
</form>
</div>
</div>
</body>
</html>

BELOW IS JAVASCRIPT COED
function formValidation()
{
var uname = document.registration.fname;
var uemail = document.registration.email;

if(allLetter(uname))
{
if(ValidateEmail(uemail))
}
}
return false;

}
function allLetter(uname)
{
alert "hello";
var letters = /^[A-Za-z]+$/;
if(uname.value.match(letters))
{
return true;
}
else
{
alert('Username must have alphabet characters only');
uname.focus();
return false;
}
}
function ValidateEmail(uemail)
{
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if(uemail.value.match(mailformat))
{
return true;
}
else
{
alert("You have entered an invalid email address!");
uemail.focus();
return false;
}
}
else
{
alert('Form Succesfully Submitted');
window.location.reload()
return true;
}
}



Thanks

Sunny
New php-forum User
New php-forum User
Posts: 23
Joined: Wed Nov 30, 2011 6:51 am

Re: Not Checking Validation

Post by Sunny » Wed Oct 30, 2013 9:27 pm

Hi

In the below code it is not performing validation .

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Registration Form</title>
<link href="style/style.css" rel="stylesheet" type="text/css" media="all" />

<SCRIPT type="text/javascript">
alert("hello");
function validate(form) {
OK=false;

var letters = /^[A-Za-z]+$/;
if (document.forms["registration"]["fname"].value.match(letters))
{
OK = true;
}
else
{
OK = false;
}
if(OK) {
form.submit();
}
else {
alert("You did it wrong!");
}
</SCRIPT>
</head>

<div id="wrap">
<div id="wrap2">
<form action="process.php" name="registration" method="post" id="register_form">
<p class="validate_msg">Please fix the errors below!</p>
<p> <label for="name">First Name</label> <input name="fname" type="text" /> <span class="val_fname"></span> </p>
<input type="submit" name="submit" onclick="validate(this.form)" value="Register">
</form>
</div>
</div>
</body>
</html>

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests