Hey Guys,
I am new to PHP and know nothing of java scripts. I have to build a web page where user enters login information at the time of registration. I have taken help of a PHP tool to generate the required scripts. Now in that I have to incorporate a functionality to check the password length and give appropiate message if password is too short. I think I could enter this functionality through javascripts but I don't know how. I am attaching the file in which the PHP scripts are written. Please help me out.

This is how you get the length of a string.

var stringlen = stringvarname.length;

BTW: its all html when it hits the browser

Hi,

Replace the ew_ValidateForm javascript function with

function ew_ValidateForm(fobj) {
	if (fobj.a_confirm && fobj.a_confirm.value == "F")
		return true;
	var i, elm, aelm, infix;
	var rowcnt = (fobj.key_count) ? Number(fobj.key_count.value) : 1;
	for (i=0; i<rowcnt; i++) {
		infix = (fobj.key_count) ? String(i+1) : "";
		elm = fobj.elements["x" + infix + "_user_name"];
		if (elm && !ew_HasValue(elm)) {
			if (!ew_OnError(elm, "Please enter required field - User Name"))
				return false;
		}
		elm = fobj.elements["x" + infix + "_password"];
		if (elm && !ew_HasValue(elm)) {
			if (!ew_OnError(elm, "Please enter required field - Password"))
				return false;
		}
		//Added by vivek Rawat here to check the length of pasword
		minlength=6;
		if (elm)
		{
			if(elm.value.length < minlength)
			{
				alert("Password should have minimum "+minlength+" characters");
				return false;
			}
		}
		//end added by vivek rawat
		elm = fobj.elements["x" + infix + "_user_id"];
		if (elm && !ew_HasValue(elm)) {
			if (!ew_OnError(elm, "Please enter required field - User ID"))
				return false;
		}
		elm = fobj.elements["x" + infix + "_user_id"];
		if (elm && !ew_CheckInteger(elm.value)) {
			if (!ew_OnError(elm, "Incorrect integer - User ID"))
				return false; 
		}
		elm = fobj.elements["x" + infix + "_user_access_rights"];
		if (elm && !ew_HasValue(elm)) {
			if (!ew_OnError(elm, "Please enter required field - User Access Rights"))
				return false;
		}
	}
	return true;
}

Check for the code that I have added.
in the block
//Added by vivek Rawat here to check the length of pasword

Thanx a ton vicky. The code is working perfectly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.