473,385 Members | 1,392 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

password field validation - help

I've been trying for the past week to put a simple code together. I
have done a LOT of searching, found scripts showing the functions I
would like to use, however when I mix them it all goes wrong, somehow
I always end up with error messages and functions not working right.
Can someone please help me?

I have a form, inside is 1 Text Field and 2 Password Fields. What I'm
looking to do is:
- Make sure password fields are equal
- Set Minimum/Maximum amount of characters in each field
- Disable submit button after clicking submit

I plan to add more text fields in the future. Will I be able to? I
know how to add it in the form, but how do I change the script?

Any help is appreciated. What I have so far may not be worth a look,
it's not even working, I don't know why, but here is goes:

<html>
<head>
<title>Test Page 01</title>
<script language="JavaScript">
<!--
function checkPw(element) {
pw1 = document.FormName.pw1.value;
pw2 = element.value;
if (pw1 != pw2) {
alert ("Passwords do not match. Please re-enter.");
document.FormName.pw1.value="";
document.FormName.pw2.value="";
document.FormName.pw1.focus();
return false;
}
}
// -->
</script>
</head>
<body>
<form action="http://www.photoshelf.net/cgi-bin/mailto"
onsubmit="return FrontPage_Form1_Validator(this)" method="post"
name="FormName">
<input type="hidden" name="THANKURL"
value="http://www.somepage.org/ok.htm">
<input type="hidden" name="RECIPIENT" value="so*****@somepage.com">
<input type="text" name="UserName" size="20" maxlength="60">
<input type="password" name="pw1" size="20" maxlength="60">
<input type="password" name="pw2" size="20" maxlength="60"
onBlur="checkPw(this)"><br>
<input type="submit" value="Submit Application" onClick="if(this.value
== 'Continue') this.form.submit();">
</form>
</body>
</html>

Thanks. Mike
Jul 20 '05 #1
7 8668
ms*****@photoshelf.net (Mike) writes:
I have a form, inside is 1 Text Field and 2 Password Fields. What I'm
looking to do is:
- Make sure password fields are equal
- Set Minimum/Maximum amount of characters in each field
- Disable submit button after clicking submit

I plan to add more text fields in the future. Will I be able to?
Sure.
I know how to add it in the form, but how do I change the script?
It's modular. You add clauses for each thing you want to test.

Remember the <!DOCTYPE ...> declaration. It's required in HTML
<html>
<head>
<title>Test Page 01</title>
<script language="JavaScript">
The type attribute is required in HTML 4, and is always sufficient:
<script type="text/javascript">
<!--
Not necessary.
function checkPw(element) {
You call this function in the second password field's onblur handler.
Just wait until submission.

You only need one function to validate. We call it from the onsubmit
handler with the form as argument.
---
function validate(form) {
// check user anme between 6 and 10 characters:
var user = form.elements[UserName];
if (user.value.length < 6 || user.value.length > 10) {
alert("User name must be between 6 and 10 characters!");
user.focus();
return false;
}
// passwords equal and between 6 and 8 characters
var pwd1 = form.elements["pw1"];
var pwd2 = form.elements["pw2"];
if (pwd1.value != pwd2.value) {
alert("Passwords must be equal!");
pwd1.focus();
return false;
}
if (pwd1.length < 6 || pwd1.length > 8) {
alert("Passwords must be between 6 and 8 characters!");
pwd1.focus();
return false;
}
// form is ok, prevent further submit.
var submit = form.elements["submitButton"];
submit.value = "Already submitted!";
submit.disabled = true;
return true;
}
---
<form action="http://www.photoshelf.net/cgi-bin/mailto"
onsubmit="return FrontPage_Form1_Validator(this)" method="post"
name="FormName">
change onsubmit to
onsubmit="return validate(this);"
or whatever function name you want.
<input type="submit" value="Submit Application" onClick="if(this.value
== 'Continue') this.form.submit();">


Give the submit button a name so we can find and disable it.

Good luck
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
Mike wrote on 29 Nov 2003:
I've been trying for the past week to put a simple code
together. I have done a LOT of searching, found scripts showing
the functions I would like to use, however when I mix them it
all goes wrong, somehow I always end up with error messages and
functions not working right. Can someone please help me?

I have a form, inside is 1 Text Field and 2 Password Fields.
What I'm looking to do is:
- Make sure password fields are equal
- Set Minimum/Maximum amount of characters in each field
- Disable submit button after clicking submit
That's a dangerous thing to do. If a user clicks the 'Back' button,
the submit button will still be disabled (control states are usually
saved) and the user has to go back again, then forward to restore the
initial settings. It might not matter in this case, though (due to
the nature of the form).
I plan to add more text fields in the future. Will I be able to?
I know how to add it in the form, but how do I change the
script?
The text fields have nothing to do with the validation of the
password fields so you could add anything you like and it will have
no effect, or does the number of characters condition you state above
apply to literally /every/ field? If so, and the limits are the same
for all fields, or all types of field (60 for password types, 30 for
text, 1000 for textarea, etc), there is no problem. If not (the
limits vary from field to field) it could become a little more
complicated. You'll have to explain more about the changes you might
make.
<script language="JavaScript">
There is no need to use the language attribute (it is, in fact,
discouraged), but you /must/ use type (type="text/javascript")
<!--
You don't need to use SGML comments in SCRIPT blocks.
function checkPw(element) {
pw1 = document.FormName.pw1.value;
You should use the forms and elements collections, like so:

pw1 = document.forms['FormName'].elements['pw1'].value;

It aids in compatibility. You should also use the var keyword to
declare the variable, otherwise it ends up becoming a global.
pw2 = element.value;
if (pw1 != pw2) {
alert ("Passwords do not match. Please re-enter.");
You should qualify that using window. That is, window.alert(...). The
collections comment above applies to these, too:
document.FormName.pw1.value="";
document.FormName.pw2.value="";
document.FormName.pw1.focus();
return false;
Returning false should not be necessary here (and may not do
anything, anyway). The focus() call should keep the box in focus.
}
Not that it matters here, due to what I just wrote, but in future, I
would suggest that if you return a value for one code path, every
code path should return a value.
}
// -->
</script>
</head>
<body>
<form action="http://www.photoshelf.net/cgi-bin/mailto"
onsubmit="return FrontPage_Form1_Validator(this)" method="post"
name="FormName">
You're using intrinsic events, but you didn't (in this sample) set
the default scripting language. This is invalid HTML. Place the
following META element in the document HEAD:

<META http-equiv="Content-Script-Type" content="text/javascript">
<input type="hidden" name="THANKURL"
value="http://www.somepage.org/ok.htm">
<input type="hidden" name="RECIPIENT"
value="so*****@somepage.com">
This is a /huge/ security risk. Never use a mail form that requires a
full "To:" address - it's an easy target for spam (both for receiving
it, and sending it).
<input type="text" name="UserName"
size="20" maxlength="60"> <input type="password" name="pw1"
size="20" maxlength="60"> <input type="password" name="pw2"
size="20" maxlength="60" onBlur="checkPw(this)"><br>
The check should really be done upon submission. If I choose to do
something else before completing a matching password (including
changing my original password), I'll be trapped in this input field.
There's also no need to pass the entire object: just pass the value
using this.value.
<input type="submit" value="Submit Application"
onClick="if(this.value == 'Continue') this.form.submit();">


From what you've shown, that onclick event doesn't seem to do
anything. It would have been helpful if you had shown the function
called by the form's onsubmit event.

Apply the suggestions I've made so far. If it's not enough, say so,
and include the function called by the onsubmit event and explain
your restrictions in more detail, and I'll try again.

Good luck,
Mike

--
Michael Winter
M.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)
Jul 20 '05 #3
Michael Winter <M.******@blueyonder.co.uk.invalid> wrote in message news:<Xn*******************************@193.38.113 .46>...
Mike wrote on 29 Nov 2003:
I've been trying for the past week to put a simple code
together. I have done a LOT of searching, found scripts showing
the functions I would like to use, however when I mix them it
all goes wrong, somehow I always end up with error messages and
functions not working right. Can someone please help me?

I have a form, inside is 1 Text Field and 2 Password Fields.
What I'm looking to do is:
- Make sure password fields are equal
- Set Minimum/Maximum amount of characters in each field
- Disable submit button after clicking submit


That's a dangerous thing to do. If a user clicks the 'Back' button,
the submit button will still be disabled (control states are usually
saved) and the user has to go back again, then forward to restore the
initial settings. It might not matter in this case, though (due to
the nature of the form).
I plan to add more text fields in the future. Will I be able to?
I know how to add it in the form, but how do I change the
script?


The text fields have nothing to do with the validation of the
password fields so you could add anything you like and it will have
no effect, or does the number of characters condition you state above
apply to literally /every/ field? If so, and the limits are the same
for all fields, or all types of field (60 for password types, 30 for
text, 1000 for textarea, etc), there is no problem. If not (the
limits vary from field to field) it could become a little more
complicated. You'll have to explain more about the changes you might
make.
<script language="JavaScript">


There is no need to use the language attribute (it is, in fact,
discouraged), but you /must/ use type (type="text/javascript")
<!--


You don't need to use SGML comments in SCRIPT blocks.
function checkPw(element) {
pw1 = document.FormName.pw1.value;


You should use the forms and elements collections, like so:

pw1 = document.forms['FormName'].elements['pw1'].value;

It aids in compatibility. You should also use the var keyword to
declare the variable, otherwise it ends up becoming a global.
pw2 = element.value;
if (pw1 != pw2) {
alert ("Passwords do not match. Please re-enter.");


You should qualify that using window. That is, window.alert(...). The
collections comment above applies to these, too:
document.FormName.pw1.value="";
document.FormName.pw2.value="";
document.FormName.pw1.focus();
return false;


Returning false should not be necessary here (and may not do
anything, anyway). The focus() call should keep the box in focus.
}


Not that it matters here, due to what I just wrote, but in future, I
would suggest that if you return a value for one code path, every
code path should return a value.
}
// -->
</script>
</head>
<body>
<form action="http://www.photoshelf.net/cgi-bin/mailto"
onsubmit="return FrontPage_Form1_Validator(this)" method="post"
name="FormName">


You're using intrinsic events, but you didn't (in this sample) set
the default scripting language. This is invalid HTML. Place the
following META element in the document HEAD:

<META http-equiv="Content-Script-Type" content="text/javascript">
<input type="hidden" name="THANKURL"
value="http://www.somepage.org/ok.htm">
<input type="hidden" name="RECIPIENT"
value="so*****@somepage.com">


This is a /huge/ security risk. Never use a mail form that requires a
full "To:" address - it's an easy target for spam (both for receiving
it, and sending it).
<input type="text" name="UserName"
size="20" maxlength="60"> <input type="password" name="pw1"
size="20" maxlength="60"> <input type="password" name="pw2"
size="20" maxlength="60" onBlur="checkPw(this)"><br>


The check should really be done upon submission. If I choose to do
something else before completing a matching password (including
changing my original password), I'll be trapped in this input field.
There's also no need to pass the entire object: just pass the value
using this.value.
<input type="submit" value="Submit Application"
onClick="if(this.value == 'Continue') this.form.submit();">


From what you've shown, that onclick event doesn't seem to do
anything. It would have been helpful if you had shown the function
called by the form's onsubmit event.

Apply the suggestions I've made so far. If it's not enough, say so,
and include the function called by the onsubmit event and explain
your restrictions in more detail, and I'll try again.

Good luck,
Mike


Hi Mike: Without typing anything on the fields and simply clicking on
submit, IE6 errors:
"Line 22, Char 1, Object Expected"

I'm sure I screwed up!:

<html>
<head>
<title>Test Page 01</title>
<META http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function checkPw(element) {
pw1 = document.forms['FormName'].elements['pw1'].value;

pw2 = element.value;
if (pw1 != pw2) {
window.alert ("Passwords do not match. Please re-enter.");
document.FormName.pw1.value="";
window.alert ("Please enter a password.");
document.FormName.pw2.value="";
window.alert ("Please re-enter your password.");
document.FormName.pw1.focus();
}
// -->
</script>
</head>
<body>
<form action="http://www.photoshelf.net/cgi-bin/mailto"
onsubmit="return FrontPage_Form1_Validator(this)" method="post"
name="FormName">
<input type="text" name="UserName" size="20" maxlength="60">
<input type="password" name="pw1" size="20" maxlength="60">
<input type="password" name="pw2" size="20" maxlength="60"
"this.value"><br>
<input type="submit" value="Submit Application"
onSubmit="if(this.value == 'Continue') this.form.submit();">
</body>
</html>

Thanks in advance for all replies. Mike
Jul 20 '05 #4
Mike wrote on 30 Nov 2003:
<html>
<head>
<title>Test Page 01</title>
<META http-equiv="Content-Script-Type"
content="text/javascript"> <script type="text/javascript">
function checkPw(element) {
pw1 = document.forms['FormName'].elements['pw1'].value;

pw2 = element.value;
if (pw1 != pw2) {
window.alert ("Passwords do not match. Please
re-enter."); document.FormName.pw1.value="";
window.alert ("Please enter a password.");
document.FormName.pw2.value="";
window.alert ("Please re-enter your password.");
document.FormName.pw1.focus();
}
// -->
</script>
</head>
<body>
<form action="http://www.photoshelf.net/cgi-bin/mailto"
onsubmit="return FrontPage_Form1_Validator(this)" method="post"
name="FormName">
<input type="text" name="UserName" size="20" maxlength="60">
<input type="password" name="pw1" size="20" maxlength="60">
<input type="password" name="pw2" size="20" maxlength="60"
"this.value"><br>
<input type="submit" value="Submit Application"
onSubmit="if(this.value == 'Continue') this.form.submit();">
</body>
</html>


If this is exactly what you are testing, it's because the function
(used in the form onsubmit event) FrontPage_Form1_Validator() doesn't
exist.

You should remove the closing SGML comment (// -->) at the end of the
script block.

Finally, you should remove the onsubmit event on the submit button.
INPUT elements (of any type) don't have such an event, so it means
and does nothing.

Here's some advice to help you do the other things you asked about in
your original post:

You've already got the maximum lengths restricted in your HTML. To
set a minimum length, use [control reference].value.length. For
example:

document.forms['FormName'].elements['pw1'].value.length

To disable the submit button, place the following at the end of the
validation script so it will be executed when the form validates
correctly:

document.forms['FormName'].elements['submitButtonName'].disabled =
true;

If you make all these changes and add a proper onsubmit event handler
for the form, your document above would look something like:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<HTML>
<HEAD>
<META http-equiv="Content-Script-Type" content="text/javascript">

<TITLE>Test Page 01</TITLE>

<SCRIPT type="text/javascript">
function checkPw(form) {
var pw1 = form.elements['pw1'];
var pw2 = form.elements['pw2'];
var minPasswordLength = 6;

// Check password length
if ((minPasswordLength > pw1.value.length)
|| (minPasswordLength > pw2.value.length)) {
window.alert(
'Passwords must be at least ' + minPasswordLength
+ ' characters long.');
pw1.focus();
return false;
}

// Check password match
if (pw1.value != pw2.value) {
window.alert(
'The passwords do not match. Please re-enter.');
pw1.value = '';
pw2.value = '';
pw1.focus();
return false;
}

// By now, the passwords have been validated. The form can be
// submitted, and the submit button (I've named it 'apply'
// for this example) can be disabled.
form.elements['apply'].disabled = true;
return true;
}
</SCRIPT>
</HEAD>

<BODY>
<FORM name="FormName" method="post"
action="http://www.photoshelf.net/cgi-bin/mailto"
onsubmit="return checkPw(this)">
<INPUT type="text" name="UserName" size="20" maxlength="60">
<INPUT type="password" name="pw1" size="20" maxlength="60">
<INPUT type="password" name="pw2" size="20" maxlength="60">
<INPUT type="submit" name="apply" value="Submit Application">
</BODY>
</HTML>

Hope this helps,
Mike

Sorry, I didn't mean to write this for you, but there were quite a
few mistakes creeping in that would take too much explanation to fix.
I think I was giving you too much new information without explaining
it properly. My fault.

--
Michael Winter
M.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)
Jul 20 '05 #5
Michael Winter <M.******@blueyonder.co.uk.invalid> wrote in message news:<Xn*******************************@193.38.113 .46>...
Mike wrote on 30 Nov 2003:
<html>
<head>
<title>Test Page 01</title>
<META http-equiv="Content-Script-Type"
content="text/javascript"> <script type="text/javascript">
function checkPw(element) {
pw1 = document.forms['FormName'].elements['pw1'].value;

pw2 = element.value;
if (pw1 != pw2) {
window.alert ("Passwords do not match. Please
re-enter."); document.FormName.pw1.value="";
window.alert ("Please enter a password.");
document.FormName.pw2.value="";
window.alert ("Please re-enter your password.");
document.FormName.pw1.focus();
}
// -->
</script>
</head>
<body>
<form action="http://www.photoshelf.net/cgi-bin/mailto"
onsubmit="return FrontPage_Form1_Validator(this)" method="post"
name="FormName">
<input type="text" name="UserName" size="20" maxlength="60">
<input type="password" name="pw1" size="20" maxlength="60">
<input type="password" name="pw2" size="20" maxlength="60"
"this.value"><br>
<input type="submit" value="Submit Application"
onSubmit="if(this.value == 'Continue') this.form.submit();">
</body>
</html>


If this is exactly what you are testing, it's because the function
(used in the form onsubmit event) FrontPage_Form1_Validator() doesn't
exist.

You should remove the closing SGML comment (// -->) at the end of the
script block.

Finally, you should remove the onsubmit event on the submit button.
INPUT elements (of any type) don't have such an event, so it means
and does nothing.

Here's some advice to help you do the other things you asked about in
your original post:

You've already got the maximum lengths restricted in your HTML. To
set a minimum length, use [control reference].value.length. For
example:

document.forms['FormName'].elements['pw1'].value.length

To disable the submit button, place the following at the end of the
validation script so it will be executed when the form validates
correctly:

document.forms['FormName'].elements['submitButtonName'].disabled =
true;

If you make all these changes and add a proper onsubmit event handler
for the form, your document above would look something like:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<HTML>
<HEAD>
<META http-equiv="Content-Script-Type" content="text/javascript">

<TITLE>Test Page 01</TITLE>

<SCRIPT type="text/javascript">
function checkPw(form) {
var pw1 = form.elements['pw1'];
var pw2 = form.elements['pw2'];
var minPasswordLength = 6;

// Check password length
if ((minPasswordLength > pw1.value.length)
|| (minPasswordLength > pw2.value.length)) {
window.alert(
'Passwords must be at least ' + minPasswordLength
+ ' characters long.');
pw1.focus();
return false;
}

// Check password match
if (pw1.value != pw2.value) {
window.alert(
'The passwords do not match. Please re-enter.');
pw1.value = '';
pw2.value = '';
pw1.focus();
return false;
}

// By now, the passwords have been validated. The form can be
// submitted, and the submit button (I've named it 'apply'
// for this example) can be disabled.
form.elements['apply'].disabled = true;
return true;
}
</SCRIPT>
</HEAD>

<BODY>
<FORM name="FormName" method="post"
action="http://www.photoshelf.net/cgi-bin/mailto"
onsubmit="return checkPw(this)">
<INPUT type="text" name="UserName" size="20" maxlength="60">
<INPUT type="password" name="pw1" size="20" maxlength="60">
<INPUT type="password" name="pw2" size="20" maxlength="60">
<INPUT type="submit" name="apply" value="Submit Application">
</BODY>
</HTML>

Hope this helps,
Mike

Sorry, I didn't mean to write this for you, but there were quite a
few mistakes creeping in that would take too much explanation to fix.
I think I was giving you too much new information without explaining
it properly. My fault.


Excellent, worked beautiful, I can take it from here! Thanks a lot,
you saved me a lot of time. Thanks.
Mike
Jul 20 '05 #6
ms*****@photoshelf.net (Mike) wrote in message news:<5e*************************@posting.google.c om>...
Michael Winter <M.******@blueyonder.co.uk.invalid> wrote in message news:<Xn*******************************@193.38.113 .46>...
Mike wrote on 30 Nov 2003:
<html>
<head>
<title>Test Page 01</title>
<META http-equiv="Content-Script-Type"
content="text/javascript"> <script type="text/javascript">
function checkPw(element) {
pw1 = document.forms['FormName'].elements['pw1'].value;

pw2 = element.value;
if (pw1 != pw2) {
window.alert ("Passwords do not match. Please
re-enter."); document.FormName.pw1.value="";
window.alert ("Please enter a password.");
document.FormName.pw2.value="";
window.alert ("Please re-enter your password.");
document.FormName.pw1.focus();
}
// -->
</script>
</head>
<body>
<form action="http://www.photoshelf.net/cgi-bin/mailto"
onsubmit="return FrontPage_Form1_Validator(this)" method="post"
name="FormName">
<input type="text" name="UserName" size="20" maxlength="60">
<input type="password" name="pw1" size="20" maxlength="60">
<input type="password" name="pw2" size="20" maxlength="60"
"this.value"><br>
<input type="submit" value="Submit Application"
onSubmit="if(this.value == 'Continue') this.form.submit();">
</body>
</html>


If this is exactly what you are testing, it's because the function
(used in the form onsubmit event) FrontPage_Form1_Validator() doesn't
exist.

You should remove the closing SGML comment (// -->) at the end of the
script block.

Finally, you should remove the onsubmit event on the submit button.
INPUT elements (of any type) don't have such an event, so it means
and does nothing.

Here's some advice to help you do the other things you asked about in
your original post:

You've already got the maximum lengths restricted in your HTML. To
set a minimum length, use [control reference].value.length. For
example:

document.forms['FormName'].elements['pw1'].value.length

To disable the submit button, place the following at the end of the
validation script so it will be executed when the form validates
correctly:

document.forms['FormName'].elements['submitButtonName'].disabled =
true;

If you make all these changes and add a proper onsubmit event handler
for the form, your document above would look something like:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<HTML>
<HEAD>
<META http-equiv="Content-Script-Type" content="text/javascript">

<TITLE>Test Page 01</TITLE>

<SCRIPT type="text/javascript">
function checkPw(form) {
var pw1 = form.elements['pw1'];
var pw2 = form.elements['pw2'];
var minPasswordLength = 6;

// Check password length
if ((minPasswordLength > pw1.value.length)
|| (minPasswordLength > pw2.value.length)) {
window.alert(
'Passwords must be at least ' + minPasswordLength
+ ' characters long.');
pw1.focus();
return false;
}

// Check password match
if (pw1.value != pw2.value) {
window.alert(
'The passwords do not match. Please re-enter.');
pw1.value = '';
pw2.value = '';
pw1.focus();
return false;
}

// By now, the passwords have been validated. The form can be
// submitted, and the submit button (I've named it 'apply'
// for this example) can be disabled.
form.elements['apply'].disabled = true;
return true;
}
</SCRIPT>
</HEAD>

<BODY>
<FORM name="FormName" method="post"
action="http://www.photoshelf.net/cgi-bin/mailto"
onsubmit="return checkPw(this)">
<INPUT type="text" name="UserName" size="20" maxlength="60">
<INPUT type="password" name="pw1" size="20" maxlength="60">
<INPUT type="password" name="pw2" size="20" maxlength="60">
<INPUT type="submit" name="apply" value="Submit Application">
</BODY>
</HTML>

Hope this helps,
Mike

Sorry, I didn't mean to write this for you, but there were quite a
few mistakes creeping in that would take too much explanation to fix.
I think I was giving you too much new information without explaining
it properly. My fault.


Excellent, worked beautiful, I can take it from here! Thanks a lot,
you saved me a lot of time. Thanks.
Mike


One last thing, to control minimum length on text field, I should add
the line below to the script right?

document.forms['FormName'].elements['UserName'].value.length

Where in the script? Does location matter?
Thanks again. Mike
Jul 20 '05 #7
Mike wrote on 06 Dec 2003:

<snipped script>
One last thing, to control minimum length on text field, I
should add the line below to the script right?

document.forms['FormName'].elements['UserName'].value.length

Where in the script? Does location matter?


The minimum length is already checked by the script I wrote:

function checkPw(form) {
var pw1 = form.elements['pw1'];
var pw2 = form.elements['pw2'];
var minPasswordLength = 6;

// Check password length
if ((minPasswordLength > pw1.value.length)
|| (minPasswordLength > pw2.value.length)) {
window.alert(
'Passwords must be at least ' + minPasswordLength
+ ' characters long.');
pw1.focus();
return false;
}

// Omitted the rest of the script...

If you want to change the minimum length, change the initial value of
the minPasswordLength variable. If you want to impose minimum limits
on other fields, copy that if statement block and alter it as needed.
For example:

// To check username length
var username = form.elements['UserName'];
var minUsernameLength = 4;

if (minUsernameLength > username.value.length) {
window.alert(
'Your username must be at least ' + minUsernameLength
+ ' characters long.');
username.focus();
return false;
}

Hope that helps,
Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk")
Jul 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Doslil | last post by:
I am trying to validate the fields in my database.I have already validated the fields to check for not null.Here is what I have written for Numeric and text field. Private Function EENUM() On...
2
by: Joey P | last post by:
Hi all, I am doing a project for university whereby i have to implement a simple database related to a frozen foods company. I am having some trouble though creating a validation rule for one...
1
by: dwa | last post by:
All, We're trying to determine how to deal with password fields losing their state on a post back. We've got a form that implements post backs to carry out server side processing. As a result...
5
by: Chris | last post by:
why is it that password fields: <asp:TextBox Id="txtuserpassword1" TextMode="password" class="textbox" maxlength="20" Columns="15" Runat="Server" /><br> clear everytime validation kicks in or...
15
by: Eugene Anthony | last post by:
Is this method of validation for password and username considered to be secured. In my previous post I was given a solution that uses command object and the values are parsed by parameters. But the...
8
by: Bhagya | last post by:
I am doing client side validation in my page. The password field does not retain its value. Pls help
10
by: canam | last post by:
Hi: I hope someone can help me. Is there a way to add a password to a particular field in the event that the validation rule must be over written? I've created an input form in a...
3
by: Nelluru | last post by:
Hi, I want to open user details or some data pages in a new window after he enters the username and password. I am able to open in a new window but the problem is that i am not able to...
0
by: bienwell | last post by:
Thanks for your help. <wisccal@googlemail.comwrote in message news:60d1bad3-1e68-4a1f-bf2a-fd7b53153cd2@b64g2000hsa.googlegroups.com...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.