SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: too short words

  1. #1
    Almeaty Member
    Join Date
    Jul 2000
    Location
    Nowhere
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To make a minimum using PH you can:

    if (strlen($username) < 6) {
    print "Username must be greater that 6 characters.";
    }

    Peter

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2001
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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>

  5. #5
    SitePoint Columnist Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  6. #6
    SitePoint Enthusiast
    Join Date
    Jan 2001
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  7. #7
    Almeaty Member
    Join Date
    Jul 2000
    Location
    Nowhere
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •