oh, i've got something too trivial but yet i don't know it... how can i hinder the user from entering too short words? so the system will say "sorry, your username is too short"
thx.
| SitePoint Sponsor |


oh, i've got something too trivial but yet i don't know it... how can i hinder the user from entering too short words? so the system will say "sorry, your username is too short"
thx.





Using straight html make the maxlength attribute set to whatever like
<input type="text" name="username" size=10 maxlength=10>
This would stop letting you type in stuff after 10 as for doing with php you simply would use
if (strlen($username) > 10) {
print "Username must be under 10 characters.";
}
Please don't PM me with questions.
Use the forums, that is what they are here for.





To make a minimum using PH you can:
if (strlen($username) < 6) {
print "Username must be greater that 6 characters.";
}
Peter
how about simple form validation with javascript.
this way, you don't have to reload the page. it will
stop this error before submitting.
<html>
<head>
<script language="JavaScript">
<!--
function validate_form()
{
var f = document.someform;
var valid_check = true;
if (f.fieldname.length < 10)
{
alert("username too short");
valid_check = false;
}
return valid_check;
}
// -->
</script>
</head>
<body>
<form name=someform action="./somthing.php" method="post" onsubmit="return validate_form();">
<!-- all your form stuff -->
</form>
</body>
</html>





Quick point - although javascript checks are great for the user (they let them get things right before they even submit the form) you should NEVER rely on them from a security point of view. Remember that a determined user could turn javascript off or even post stuff from their own custom form running elsewhere. By all means use javscript checks but always make sure they are backed up by server side checks in your scripts to ensure malicious users don't cause probolems.
very good point indeed skunk. always have some other form of security checking. what I posted is well suited for registration type forms. an actuall login form, while this is still a nicety to use js, there needs to be some sort of authentication within the recieving script as well.


well, i already implemented the server-side verification. but i must say that i HATE javascript and never use it for form checks etc. maybe for some rollover effects, but that's all...
thanks to you folks btw![]()
Bookmarks