Limit TextField

Results 1 to 7 of 7
  1. #1
    人◕ ‿‿ ◕人 Forean is offline
    MemberRank
    Jul 2008 Join Date
    1,183Posts

    Limit TextField

    okay guys Im beginning at php, and as the title says i want to limit the text-field

    like "ON THE REGISTER PAGE"

    Username : This-is-a-username

    but thats a total of 18 Characters Aka letters.. And i want them to only be able to put 12 For Example

    Username : This-is-a-us

    After that it wont let them put anymore even if they spam letters :P

    Any ideas?
    Last edited by Forean; 02-08-09 at 06:43 AM.


  2. #2
    Member Akizuma is offline
    MemberRank
    Aug 2009 Join Date
    New YorkLocation
    66Posts

    Re: Limit TextField

    Wait you talking about game or a web script?

  3. #3
    人◕ ‿‿ ◕人 Forean is offline
    MemberRank
    Jul 2008 Join Date
    1,183Posts

    Re: Limit TextField

    Updated, this is for the Register Page.

  4. #4
    Account Upgraded | Title Enabled! Guy is offline
    MemberRank
    Apr 2009 Join Date
    919Posts

    Re: Limit TextField

    For a client-sided fix, use the MAXLENGTH attribute; in PHP, just check the length of the entered field using the string length function, strlen:

    Code:
    <?php
     if( strlen( $_POST['username'] ) > 10 )
     {
      die( "That name is too long" );
     }
     else
     {
      // Continue with registration..
     }
    ?>
    Last edited by Guy; 02-08-09 at 07:10 AM.

  5. #5

    Re: Limit TextField

    strlen in PHP,

    maxlength in HTML.

  6. #6
    Account Upgraded | Title Enabled! Guy is offline
    MemberRank
    Apr 2009 Join Date
    919Posts

    Re: Limit TextField

    Quote Originally Posted by Linear88 View Post
    strlen in PHP,

    maxlength in HTML.
    It's the maxlength attribute; e.g.

    Code:
    <input type="..." maxlength="10" />

  7. #7
    人◕ ‿‿ ◕人 Forean is offline
    MemberRank
    Jul 2008 Join Date
    1,183Posts

    Re: Limit TextField

    i tryed the input type and it made and extra bar above the username bar O.o so let me try to php one



Advertisement