Solved

Add Password confirm validation to my code

Posted on 2004-04-30
8
378 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
  • 5
  • 3
8 Comments
 
LVL 9

Expert Comment

by:CFDevHead
Comment Utility
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
Comment Utility
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
Comment Utility
did try my code
working example http://spiraldev.com/ee/ee.cfm
0
 
LVL 9

Expert Comment

by:CFDevHead
Comment Utility
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:asamuel
Comment Utility
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
Comment Utility
put this at the top of the posting page <cfheader name="cache-control" value="Public">
0
 

Author Comment

by:asamuel
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now