Solved

How to add PHP funtion Confirm Password

Posted on 2008-10-30
2
2,742 Views
Last Modified: 2008-12-08
I have this script and I would like to add a function to confirm password i have a form that has 2 fields one of the password and the other to confirm here is the link to see the script:
http://chains.ch/2008/01/26/ajax-form-validation-sform/ 
<?
 

/*

 * This is the PHP script to validate the form over AJAX

 * Validations types possible:

 *

 * - alpha

 * - alphanum

 * - date

 * - email

 * - number

 * - url

 *

 */
 
 

// Start the main function

StartValidate();
 

function StartValidate() {

	

	// Assign some var's for the requests

	$required = $_GET["required"];

	$type = $_GET["type"];

	$value = $_GET["value"];
 

	// This is the function to check if a field is even required or not

	// So it's useful if you only want to check if it isn't empty

	validateRequired($required, $value, $type);
 

	switch ($type) {

		case 'number':

			validateNumber($value);

			break;

		case 'alphanum':

			validateAlphanum($value);

			break;

		case 'alpha':

			validateAlpha($value);

			break;

		case 'date':

			validateDate($value);

			break;

		case 'email':

			validateEmail($value);

			break;

		case 'url':

			validateUrl($value);

			break;

	}

}
 

// The function to check if a field is required or not

function validateRequired($required, $value, $type) {

	if($required == "required") {
 

		// Check if we got an empty value

		if($value == "") {

			echo "false";

			exit();

		}

	} else {

		if($value == "") {

			echo "none";

			exit();

		}

	}

}
 

// I use regular expressions in order to check a field's input, you can

// get most of them at the Regex Library at http://www.regexlib.com

// There you can check your own regular expressions, too
 

// Validation of an Email Address

function validateEmail($value) {

	if(ereg("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$", $value, $regs)) {

		echo "true";

	} else {

		echo "false";

	}

}
 

// Validation of a date

function validateDate($value) {

	if(ereg("^(([1-9])|(0[1-9])|(1[0-2]))\/(([0-9])|([0-2][0-9])|(3[0-1]))\/(([0-9][0-9])|([1-2][0,9][0-9][0-9]))$", $value, $regs)) {

		echo "true";

	} else {

		echo "false";

	}

}
 

// Validation of an URL

function validateUrl($value) {

	if(ereg("^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&amp;%\$#\=~])*[^\.\,\)\(\s]$", $value, $regs)) {

		echo "true";

	} else {

		echo "false";

	}

}
 

// Validation of characters

function validateAlpha($value) {

	if(ereg("^[a-zA-Z]+$", $value, $regs)) {

		echo "true";

	} else {

		echo "false";

	}

}
 

// Validation of characters and numbers

function validateAlphanum($value) {

	if(ereg("^[a-zA-Z0-9]+$", $value, $regs)) {

		echo "true";

	} else {

		echo "false";

	}

}
 

// Validation of numbers

function validateNumber($value) {

	if(ereg("^[0-9]+$", $value, $regs)) {

		echo "true";

	} else {

		echo "false";

	}

}
 

?>

Open in new window

0
Comment
Question by:jd_18286
2 Comments
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 500 total points
ID: 22846842
Hi jd_18286,

The function would pretty simple, something like:

function passwordmatch($pass1, $pass2) {
     if ($pass1 === $pass2) {
           return true;
     } else {
          return false;
     }
}

All you would need to do is pass the values from the two password fields to the function in the PHP script that processes the form.
0
 

Author Comment

by:jd_18286
ID: 22851428
I tried with that but it didn't work on form the field of confirm password should be red if the entered text is not as the field of password please if u can download the script and take a look u should understand.
http://chains.ch/download/sForm.zip
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

863 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

22 Experts available now in Live!

Get 1:1 Help Now