Solved

Add Password confirm validation to my code

Posted on 2004-04-30
8
382 Views
Last Modified: 2013-12-24
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
Comment
Question by:asamuel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 9

Expert Comment

by:CFDevHead
ID: 10963589
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
 

Author Comment

by:asamuel
ID: 10963675
Thank you for replying back, the set focus is working, but if i don't type anything and submit it it go through
0
 
LVL 9

Expert Comment

by:CFDevHead
ID: 10963694
did try my code
working example http://spiraldev.com/ee/ee.cfm
0
Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

 
LVL 9

Expert Comment

by:CFDevHead
ID: 10963755
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
 

Author Comment

by:asamuel
ID: 10977907
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
 
LVL 9

Expert Comment

by:CFDevHead
ID: 10978851
put this at the top of the posting page <cfheader name="cache-control" value="Public">
0
 

Author Comment

by:asamuel
ID: 10979127
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
 
LVL 9

Accepted Solution

by:
CFDevHead earned 250 total points
ID: 10979249
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

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
What You Need to Know when Searching for a Webhost Provider
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question