Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 404
  • Last Modified:

Add Password confirm validation to my code

Hi Guys,
Below is my code, it doesn't seems the jave validation is working, can you check it out and i need to have password confirmation validate
check  



<html>
<head>
<script language='javascript'>function setFocus() {document.signForm.fname.focus();} window.onload=setFocus;
    function checkForm(){
                 theform=document.signForm

                 if (theform.fname.value==""){
                     alert("First name is required")
                     theform.fname.focus()
                     return false;
                }
                 if (theform.lname.value==""){
                     alert("Last name is required")
                     theform.lname.focus()
                     return false;
                }
                    if (theform.User_name.value==""){
                     alert("User name is required")
                     theform.User_name.focus()
                     return false;
                }
                    if (theform.user_pass.value==""){
                     alert("User password is required")
                     theform.user_pass.focus()
                     return false;
                }
                     if (theform.user_Confirm_pass.value==""){
                     alert("Confirm Password is required")
                     theform.user_Confirm_pass.focus()
                     return false;
                }
                         if (theform.Phone_No.value==""){
                     alert("Phone number is required")
                     theform.Phone_No.focus()
                     return false;
                }
                         if (theform.email.value==""){
                     alert("email address is required")
                     theform.email.focus()
                     return false;
                }
                   
     // Check that the form has an email specified in the field called "email"
     var emailaddress = theform.email.value;
var emailexp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.(([a-z]{2,3})|(aero|coop|info|museum|name))$/i;
if (!emailexp.test(emailaddress)) {
alert('Email address is missing or invalid, please check your email address')
theform.email.focus()
;return false;
}
                   
                   

<!--
//Validate Emai
;function isEmail(strFieldName,strMsg)
{
     var strEmail = strFieldName.value;
     var bolValid = true;
     if(strEmail.length == 0){
          bolValid = false;
     }
     if(strEmail.length < 7){
          bolValid = false;
     }
     if(strEmail.lastIndexOf(" ") >0){
          bolValid = false;
     }
     var intLastDot = strEmail.lastIndexOf(".")
     if(intLastDot == -1 ||  strEmail.length - intLastDot >4){
          bolValid = false;
     }
     var intAt = strEmail.lastIndexOf("@")
     if(intAt == -1 ||  strEmail.length - intAt < 5){
          bolValid = false;
     }
     if(! bolValid){
          alert(strMsg.toUpperCase() +" is either empty or is not in the correct format");
               strFieldName.focus();
               }
     return bolValid;
}
function validateForm(fObj){
     if(!isEmail(fObj["email"],"email")){
          return false;
     }
     return true;
}



// -->

               
</SCRIPT>
<title>Test Request Sign In Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.add {
      font-family: "Times New Roman", Times, serif;
      font-size: medium;
      font-style: normal;
      line-height: normal;
      font-weight: bold;
      font-variant: normal;
      color: #0000FF;
}
-->
</style>

</head>

<body>
<form action="insert.cfm" method="post" target="blank" name="signForm" onsubmit="return checkForm();validateForm(this);">
  <table width="60%" align="center" bordercolor="#990033" bgcolor="#00FFFF">
    <tr>
      <th colspan="2"> <h1 align="center"><font size="5"><strong><img src="../../logo.gif" width="56" height="62"></strong></font></h1>
        <h1 align="center"><font size="5"><strong>Add New Requester</strong></font>
        </h1>
        <p align="center">&nbsp;</p></th>
</tr>


<tr>
      <td class="add"> First name: </td>
      <td>
<input type="text"
                 name="fname"
                      
                           size="30"
                            maxlength="30">
                              


</td></tr>
      <td class="add"></tr>

<tr>
      <td class="add"> Last name: </td>
      <td>
<input type="text"
                 name="lname"
                      
                           size="30"
                            maxlength="30">
                  
</td></tr>

<tr>
      <td class="add"> User name: </td>
      <td>
<input type="text"
                 name="User_name"
                      
                           size="30"
                            maxlength="30">
                  
</td></tr>

<tr>
      <td class="add"> User Password: </td>
      <td>
<input  type="password"
                 name="user_pass"
                      
                           size="30"
                            maxlength="30">
                  
</td></tr>


<tr>
      <td class="add"> Confirm User Password: </td>
      <td>
<input
                 name="user_Confirm_pass"  type="password"
                      
                           size="30"
                            maxlength="30">
                  
</td></tr>

<tr>
      <td class="add">Phone No: </td>
      <td>
<input                 name="Phone_No" type="text"
                           size="30"
                            maxlength="30"
                         
                               validate="telephone">
            
</td></tr>



<tr>
      <td class="add">Mobile No: </td>
      <td>
<input                 name="Mobile_No" type="text"
                           size="30"
                            maxlength="30">
                         
                              
            
</td></tr>

<tr>
      <td class="add">pager No: </td>
      <td>
<input                 name="Pager_No" type="text"
                           size="30"
                            maxlength="30"
                               validate="telephone">
            
</td></tr>
<tr>
      <td class="add">Email Address: </td>
      <td>
<input                 name="email" type="text"
                           size="30"
                            maxlength="30">
                         
                         
                              
            
</td></tr>

<tr>
      <td colspan="2" align="center" > <input name="insert" type="submit" id="insert" value="submit">
</td>
</tr>

</table>
 
</form>
</body>
</html>
0
asamuel
Asked:
asamuel
  • 5
  • 3
1 Solution
 
CFDevHeadCommented:
here I think what your asking for is to have the password and confirm password match

<html>
<head>
<script language='javascript'>function setFocus() {document.signForm.fname.focus();} window.onload=setFocus;
    function checkForm(f){
                 

                 if (f.fname.value==""){
                     alert("First name is required")
                     f.fname.focus()
                     return false;
                }
                 if (f.lname.value==""){
                     alert("Last name is required")
                     f.lname.focus()
                     return false;
                }
                    if (f.User_name.value==""){
                     alert("User name is required")
                     f.User_name.focus()
                     return false;
                }
                    if (f.user_pass.value==""){
                     alert("User password is required")
                     f.user_pass.focus()
                     return false;
                }
                     if (f.user_Confirm_pass.value==""){
                     alert("Confirm Password is required")
                     f.user_Confirm_pass.focus()
                     return false;
                }
                          if (f.user_Confirm_pass.value!=f.user_pass.value){
                     alert("Confirm Password and password must match")
                     f.user_Confirm_pass.focus()
                     return false;
                }
                     if (f.Phone_No.value==""){
                     alert("Phone number is required")
                     f.Phone_No.focus()
                     return false;
                }
                     if (f.email.value==""){
                     alert("email address is required")
                     f.email.focus()
                     return false;
                }
                   
     // Check that the form has an email specified in the field called "email"
     var emailaddress = f.email.value;
var emailexp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.(([a-z]{2,3})|(aero|coop|info|museum|name))$/i;
if (!emailexp.test(emailaddress)) {
      alert('Email address is missing or invalid, please check your email address')
      f.email.focus()
      return false;
}
    }                
                   

<!--
//Validate Emai
;function isEmail(strFieldName,strMsg)
{
     var strEmail = strFieldName.value;
     var bolValid = true;
     if(strEmail.length == 0){
          bolValid = false;
     }
     if(strEmail.length < 7){
          bolValid = false;
     }
     if(strEmail.lastIndexOf(" ") >0){
          bolValid = false;
     }
     var intLastDot = strEmail.lastIndexOf(".")
     if(intLastDot == -1 ||  strEmail.length - intLastDot >4){
          bolValid = false;
     }
     var intAt = strEmail.lastIndexOf("@")
     if(intAt == -1 ||  strEmail.length - intAt < 5){
          bolValid = false;
     }
     if(! bolValid){
          alert(strMsg.toUpperCase() +" is either empty or is not in the correct format");
               strFieldName.focus();
               }
     return bolValid;
}
function validateForm(fObj){
     if(!isEmail(fObj["email"],"email")){
          return false;
     }
     return true;
}



// -->

               
</SCRIPT>
<title>Test Request Sign In Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.add {
     font-family: "Times New Roman", Times, serif;
     font-size: medium;
     font-style: normal;
     line-height: normal;
     font-weight: bold;
     font-variant: normal;
     color: #0000FF;
}
-->
</style>

</head>

<body>
<form action="insert.cfm" method="post"  name="signForm" onsubmit="return checkForm(this);">
  <table width="60%" align="center" bordercolor="#990033" bgcolor="#00FFFF">
    <tr>
      <th colspan="2"> <h1 align="center"><font size="5"><strong><img src="../../logo.gif" width="56" height="62"></strong></font></h1>
        <h1 align="center"><font size="5"><strong>Add New Requester</strong></font>
        </h1>
        <p align="center">&nbsp;</p></th>
</tr>


<tr>
      <td class="add"> First name: </td>
      <td>
<input type="text"
                name="fname"
                   
                       size="30"
                        maxlength="30">
                         


</td></tr>
      <td class="add"></tr>

<tr>
      <td class="add"> Last name: </td>
      <td>
<input type="text"
                name="lname"
                   
                       size="30"
                        maxlength="30">
               
</td></tr>

<tr>
      <td class="add"> User name: </td>
      <td>
<input type="text"
                name="User_name"
                   
                       size="30"
                        maxlength="30">
               
</td></tr>

<tr>
      <td class="add"> User Password: </td>
      <td>
<input  type="password"
                name="user_pass"
                   
                       size="30"
                        maxlength="30">
               
</td></tr>


<tr>
      <td class="add"> Confirm User Password: </td>
      <td>
<input
                name="user_Confirm_pass"  type="password"
                   
                       size="30"
                        maxlength="30">
               
</td></tr>

<tr>
      <td class="add">Phone No: </td>
      <td>
<input                name="Phone_No" type="text"
                       size="30"
                        maxlength="30"
                     
                          validate="telephone">
         
</td></tr>



<tr>
      <td class="add">Mobile No: </td>
      <td>
<input                name="Mobile_No" type="text"
                       size="30"
                        maxlength="30">
                     
                         
         
</td></tr>

<tr>
      <td class="add">pager No: </td>
      <td>
<input                name="Pager_No" type="text"
                       size="30"
                        maxlength="30"
                          validate="telephone">
         
</td></tr>
<tr>
      <td class="add">Email Address: </td>
      <td>
<input                name="email" type="text"
                       size="30"
                        maxlength="30">
                     
                     
                         
         
</td></tr>

<tr>
      <td colspan="2" align="center" > <input name="insert" type="submit" id="insert" value="submit">
</td>
</tr>

</table>
 
</form>
</body>
</html>
0
 
asamuelAuthor Commented:
Thank you for replying back, the set focus is working, but if i don't type anything and submit it it go through
0
 
CFDevHeadCommented:
did try my code
working example http://spiraldev.com/ee/ee.cfm
0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
CFDevHeadCommented:
here try this script it works a little better
<html>
<head>
<script>
// Declare Global Variables

      var formAlertMessage='There were Errors!';
      var formSubmit=1;

/*
      throwError gets called each time there is an error in the
      validation routines.
*/
function throwError (theField,theMessage) {
      formAlertMessage=formAlertMessage + "\n - " + theMessage;
      formSubmit=0;
      switchStyle(theField);
}
function switchStyle (theField) {
      theSwitch=new Function("this.style.backgroundColor='FFFFFF';this.style.color='000000';if(this.type=='text') this.select();")
      theField.style.backgroundColor='FF0000';
      theField.style.color='White';
      theField.onfocus=theSwitch;
}

/*
      formAlert displays the alert message and clears necessary variables to start
      the validation over.
*/

function formAlert() {
      alert(formAlertMessage);
      formAlertMessage='There were Errors!';
      formSubmit=1;
}


/*
      formRequired makes sure a field has been completed by the user.   In order
      for this function to work with select boxes the empty value must be set to 0
      in the form.
*/

function formRequired(theField,theMessage) {
      theField.value = theField.value.replace(/\s+$|^\s*/gi, "");
      if(theField.value == '' || theField.value == '-1' || theField.value == '0') {
            throwError(theField,theMessage);
      }
}

// form field must be composed only of numbers and letters.
function formIsAlphaNumeric(theField,theMessage) {
      theField.value = theField.value.replace(/\s+$|^\s*/gi, "");
      isAlphaNum = new RegExp ("[^0-9a-zA-Z \(\)\-\.\/]");
      if (isAlphaNum.test(theField.value)) {
            throwError(theField,theMessage);
      }
}

// form field must be composed only of numbers and letters.
function formIsSame(field1,field2,theMessage) {

      if(field1.value != field2.value) {
            throwError(field2,theMessage);
            switchStyle(field1);
      }
}

function formIsEmail (theField,theMessage) {
      var email = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
       if(!email.test(theField.value)) {
            throwError(theField,theMessage);
      }
 }

// form field must be composed only of numbers.
function formIsNumeric(theField,theMessage) {
      theField.value = theField.value.replace(/\s+$|^\s*/gi, "");
      isNum = new RegExp ("[^0-9 \(\)\.\/]");
      if (isNum.test(theField.value)) {
            throwError(theField,theMessage);
      }
}

      function submitForm(theForm) {
            // validate firstName
            formRequired(theForm.fname,'You need to enter a First Name.');
            
            //validate lastName
            formRequired(theForm.lname,'You need to enter a Last Name.');
            
            // validate password and passwordV
            formRequired(theForm.user_pass,'You need to enter a Password.');
            formRequired(theForm.user_Confirm_pass,'You need to verify your Password.');
            if(formSubmit) {
                  formIsSame(theForm.user_Confirm_pass,theForm.user_pass,'Your password and verifictation password do not match.');
            };

            // validate email
            formRequired(theForm.email,'You need to enter an Email Address.');
            if(formSubmit) {
                  formIsEmail(theForm.email,'Please enter a valid Email Address.');
            }
                        
            if(formSubmit) {
                  return false;
            } else {
                  formAlert();
                  return false;
            }
      }
</script>
<title>Test Request Sign In Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.add {
     font-family: "Times New Roman", Times, serif;
     font-size: medium;
     font-style: normal;
     line-height: normal;
     font-weight: bold;
     font-variant: normal;
     color: #0000FF;
}
-->
</style>

</head>

<body>
<form action="insert.cfm" method="post"  name="signForm" onsubmit="return submitForm(this);">
  <table width="60%" align="center" bordercolor="#990033" bgcolor="#00FFFF">
    <tr>
      <th colspan="2"> <h1 align="center"><font size="5"><strong><img src="../../logo.gif" width="56" height="62"></strong></font></h1>
        <h1 align="center"><font size="5"><strong>Add New Requester</strong></font>
        </h1>
        <p align="center">&nbsp;</p></th>
</tr>


<tr>
      <td class="add"> First name: </td>
      <td>
<input type="text"
                name="fname"
                   
                       size="30"
                        maxlength="30">
                         


</td></tr>
      <td class="add"></tr>

<tr>
      <td class="add"> Last name: </td>
      <td>
<input type="text"
                name="lname"
                   
                       size="30"
                        maxlength="30">
               
</td></tr>

<tr>
      <td class="add"> User name: </td>
      <td>
<input type="text"
                name="User_name"
                   
                       size="30"
                        maxlength="30">
               
</td></tr>

<tr>
      <td class="add"> User Password: </td>
      <td>
<input  type="password"
                name="user_pass"
                   
                       size="30"
                        maxlength="30">
               
</td></tr>


<tr>
      <td class="add"> Confirm User Password: </td>
      <td>
<input
                name="user_Confirm_pass"  type="password"
                   
                       size="30"
                        maxlength="30">
               
</td></tr>

<tr>
      <td class="add">Phone No: </td>
      <td>
<input                name="Phone_No" type="text"
                       size="30"
                        maxlength="30"
                     
                          validate="telephone">
         
</td></tr>



<tr>
      <td class="add">Mobile No: </td>
      <td>
<input                name="Mobile_No" type="text"
                       size="30"
                        maxlength="30">
                     
                         
         
</td></tr>

<tr>
      <td class="add">pager No: </td>
      <td>
<input                name="Pager_No" type="text"
                       size="30"
                        maxlength="30"
                          validate="telephone">
         
</td></tr>
<tr>
      <td class="add">Email Address: </td>
      <td>
<input                name="email" type="text"
                       size="30"
                        maxlength="30">
                     
                     
                         
         
</td></tr>

<tr>
      <td colspan="2" align="center" > <input name="insert" type="submit" id="insert" onClick="" value="submit">
</td>
</tr>

</table>
 
</form>
</body>
</html>
0
 
asamuelAuthor Commented:
This good, I have other question, When i click on submit, it goes and check if the user name exist in the database, and if yes,
i have message say that this user already exist and bring them back to this form, right now, when they go back to the form,
they get blank form, all they typed gone, so there any way they can come to the same form, and they can change it
0
 
CFDevHeadCommented:
put this at the top of the posting page <cfheader name="cache-control" value="Public">
0
 
asamuelAuthor Commented:
I still getting  blank fields, when i submitted it with exist name in the database, I use self.location, to go back, not nothing in the fields
so how to retain the data, when it go back
0
 
CFDevHeadCommented:
if you are using self.location your not going to able to have the info in there because you're actually going forward so the browser this your going to a new page. try using something like this history.go(-1)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now