Hello,

I want to write a program.

in the program i need to generate a password that contain 8 - 10 charachters.
i did it, but without regex, Can any one help me, how to do this with the regular exp ?

the criterias for the pass are:
1- the length 8 -10 chars.
2- the pass must contain just [a-z] or [A-Z] or [0-9].
3- i must use the char just once in the all pass


sorry for myweak eng
I hope that u understand me, and i hope that u help me.

thank u :)

TiTo ^_^

A regex is typically for checking/replacing a string, not creating one.

Yes, exactly

I write the code.

<html>
<head>
<title>password generaton</title>
</head>
<BODY>

<SCRIPT LANGUAGE="JavaScript">

function randomPassword()
{
	var repeats = /(.)\1/;
	var length = randomFromTo(8,12);
	chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
	pass = "";
	for(x=0;x<length;x++)
	{
		i = Math.floor(Math.random() * 62);
		pass += chars.charAt(i);
	}
	if(repeats.test(pass)){
	randomPassword();
	}
	return pass;
}

function formSubmit()
{
  passform.passbox.value = randomPassword();
  return false;
}

function randomFromTo(from, to){
       return Math.floor(Math.random() * (to - from + 1) + from);
    }

//  End -->
</script>

<table align="center" border="1">
<tr>
<td valign="middle" align="center">
<center>Random Password Generator</center>
<form name="passform">

Password: <input name="passbox" type="text" size="50" tabindex="1"></p>
<p>
<input type="button" value="Generate" onClick="javascript:formSubmit()" tabindex="2"> <input type="reset" value="Clear" tabindex="3"></p>
</form>
</td>
</tr>
</table>
</html>

but it doesn't work, it's check if the are two cahrs repeating, i.g if the pass is hello, so can to match it.


but i want to check all the pass not only every two chars
i.g: welcome, i want to match it because it's contains the lchar "e" more than once.

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.