Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 16th, 2011, 07:44 AM
Authorized User
Points: 223, Level: 4
Points: 223, Level: 4 Points: 223, Level: 4 Points: 223, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2011
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default simple form integrator using javascript functions

hi all,
i want to create a simple form with 5 fields name, email-id,password,retype password and telephone number the conditions are name & password must be valid,password and retype password should match and phone no must be of 10 digits.
i have written functions for all this in javascript.tell me how to integrate to create a simple form with above fields.

kindly please integrate the functions and give me so that when i click submit button it should accept.

below is the function,when i click submit button if any errors found it should display or else it should accept.

<html>
<head>

<SCRIPT LANGUAGE="JavaScript">

function checkForm(form) /* for user name */
{
if(form.username.value == "")
{
alert("Error: Username cannot be blank!");
form.username.focus();
return false;
}
}

function checkEmail(myForm) /* for email validation*/
{
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.emailAddr.value))
{
return (true)
}
alert("Invalid E-mail Address! Please re-enter.")
return (false)
}

function validatePwd() /*password & retype-password verification*/
{
var invalid = " ";
var minLength = 6;
var pw1 = document.myForm.password.value;
var pw2 = document.myForm.password2.value;

if (pw1 == '' || pw2 == '')
{
alert('Please enter your password twice.');
return false;
}

if (document.myForm.password.value.length < minLength) {
alert('Your password must be at least ' + minLength + ' characters long. Try again.');
return false;
}

if (document.myForm.password.value.indexOf(invalid) > -1)
{
alert("Sorry, spaces are not allowed.");
return false;
}
else
{
if (pw1 != pw2)
{
alert ("You did not enter the same new password twice. Please re-enter your password.");
return false;
}
else
{
alert('Nice job.');
return true;
}
}
}

function ValidPhone(aphone) /* phone no validation */
{
var valid = "0123456789";
if(aphone=="")
{
alert ("This field is required. Please enter phone number");
return false;
}
if(aphone.length !=10)
{
alert("Invalid phone number length! Please try again.");
return false;
}
for (var i=0; i < aphone.length; i++)
{
temp = "" + aphone.substring(i, i+1);
if (valid.indexOf(temp) == "-1")
{
alert("Invalid characters in your phone. Please try again.");
return false;
}
}
return true;
}

</script>
</HEAD>
<BODY>
<form name=myForm onSubmit="return validatePwd()">
Name:<input type=name name=name size="25">
<br>
E-Mail:<input type=email name=email size="25">
<br>
Password: <input type=password name=password maxlength=12 size="25">
<br>
Retype password: <input type=password name=password2 maxlength=12 size="25">
<br>
PhoneNo:<input type=phoneno name=phoneno maxlength=10 size="25">
<br>
<input type=submit value="Submit">
</form>
</html>
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
simple form integration functions ravi951 Javascript 0 July 16th, 2011 06:28 AM
Dynamically call javascript functions austinf Javascript 1 May 13th, 2006 07:31 AM
Executing from JavaScript C# functions see07 ASP.NET 1.x and 2.0 Application Design 1 March 1st, 2005 06:02 PM
simple C++ functions melvik C# 15 July 20th, 2004 10:21 AM
javascript functions Moharo Javascript 1 September 23rd, 2003 01:04 AM



All times are GMT -4. The time now is 08:03 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.