Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 20th, 2011, 06:27 AM
Authorized User
 
Join Date: Jul 2011
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Default reply

no problem take ur own time
  Spam!  
Old July 21st, 2011, 03:24 AM
Authorized User
 
Join Date: Jul 2011
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Default joining two functions

hi all
i have 2 javascript one is simple login form and other is username function.
i want to fit username function into login form because username function will allow special characters.
below is my login form ..
<html>
<head>
<meta charset="utf-8">
<title>Simple Registration Form</title>
<script type="text/javascript">
function checkName(form) /* for real name verification */
{
var oRE = /^[a-z0-9]+[_.-]?[a-z0-9]+$/i;
var isCorrectFormat = oRE.test(text);
if (!isCorrectFormat)
{
alert("Invalid characters in username. It can only contain...");
return false;
}


if (form.realname.value == '')
{
alert('Error: Username cannot be blank!');
form.realname.focus();
return false;
}

return true;
}

function checkEmail(form) /* for email validation */
{
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.email.value))
{
return true;
}

alert('Invalid E-mail Address! Please re-enter.');
return false;
}

function validatePwd(form) /* password & retype-password verification */
{
var invalid = ' ', minLength = 6;
var pw1 = form.password.value, pw2 = form.password2.value;

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

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

if (document.form.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('Successfull.');
return true;
}
}
}

function validPhone(form) /* phone no validation */
{
var valid = '0123456789', phone = form.phoneno.value;

if (phone == '')
{
alert('This field is required. Please enter phone number');
return false;
}

if (!phone.length > 1 || phone.length < 10)
{
alert('Invalid phone number length! Please try again.');
return false;
}

for (var i = 0; i < phone.length; i++)
{
temp = '' + phone.substring(i, i + 1);

if (valid.indexOf(temp) == -1)
{
alert('Invalid characters in your phone. Please try again.');
return false;
}
}

return true;
}

function validate()
{
var form = document.forms['form'];

if (!checkName(form) || !checkEmail(form) || !validatePwd(form) || !validPhone(form))
{
return false;
}

return true;
}
</script>
</head>
<body>

<form action="" method="post" name="form" onsubmit="return validate()">
Name: <input type="text" name="realname" size="25">
<br>
E-Mail: <input type="text" 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>
</body>
</html>

i want to include the below one in the above function so that it works perfectly
<html>
<head>
<title> Validate Username</title>
<script type="text/javascript">
function validateUsername(form)
{
var sUsername = form.value;
var oRE = /^[a-z0-9]+[_.-]?[a-z0-9]+$/i;
var isCorrectFormat = oRE.test(sUsername);
if (!isCorrectFormat)
{
alert("Incorrect format.");
textbox.select();
textbox.focus();
return false;
}
alert("Correct format");
return true;
}
</script>
</head>
<body>
<form>
<input type="text" id="txtUsername" size="30" maxlength="20" />&nbsp;<input type="button"
value="Validate" onclick="validateUsername(document.getElementById( 'txtUsername'));" />
</form>
</body>
</html>
please can you make for that me..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Password Strength Verification vinodhanandhan .NET Framework 1.x 0 December 10th, 2006 04:45 AM
login verification katie456 Access ASP 3 October 16th, 2005 01:47 PM
Email verification John K. King Javascript How-To 4 November 24th, 2004 03:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.