Jump to content

JS help


darkfreaks

Recommended Posts

how would i remove the forn name value from the following function and make it so spaces and every character/symbol is not allowed except dashes and under scores?

 

function validatePwd() {
var invalid = " "; // Invalid character is a space
var minLength = 4; // Minimum length
var maxLength = 50;//Maximum length
var pw1 = document.myForm.password.value;
// check for minimum length
if (document.myForm.password.value.length < minLength) {
alert('Your password must be at least ' + minLength + ' characters long. Try again.');
return false;
//check for maximum length
if (document.myForm.password.value.length > maxLength) {
alert('Your password must not exceed ' + minLength + ' characters long. Try again.');
return false;
}
// check for spaces
if (document.myForm.password.value.indexOf(invalid) > -1) {
alert("Sorry, spaces are not allowed.");
return false;
}
else {
alert('Nice job.');
return true;
      }
   }
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.