views:

66

answers:

5

i have a simple question..

in registration script.. how can i set the limit character of a password. sample: minimum character is 6.. so what will be the code. please help me. :-(

+1  A: 

Use the strlen() function...

Macmade
+2  A: 
function check_pass($pass, $min = 6)
{
    return (strlen($pass) >= $min);
}
fabrik
no need to use the ternary operator here. (strlen($s) >= $min) will return true or false
Sven Koschnicke
You're totally right, modified my answer.
fabrik
+1  A: 

Are you looking for this?

if (strlen($pw) >= 6)

Note that you have to do this, before encrypting with md5

JochenJung
A: 

Javascript code:

var el = document.getElementById('field_id');

if (el.value.length >= 6)
{
  alert('OOps');
}

PHP Code:

if (strlen($_POST['field_name']) >= 6)
{
  // more than six chars entered !!
}
Sarfraz
He wanted a minimum of 6, not a maximum of 6.
animuson
right. its minimum of 6.. :P
mayumi
@animuson: Yeah thanks fixed that. :)
Sarfraz
@sac, tnx for this code. :)
mayumi
A: 
<?php
$str = 'abcdef';
echo strlen($str); // 6

$str = ' ab cd ';
echo strlen($str); // 7


if (strlen($str) > 5 AND strlen($str) < 10) {
   echo "OK"
}
?>
Adnan