Professional Web Applications Themes

Space detection in text input form - PHP Development

I am trying to create a "foolproof" login. Basically people can type their name in with no password or registration, this is done on trust and so that the site can keep track of them. All the scripts to hold this in place work perfectly however I'm struggling with the handling of an input with one or more text. The sql type of username is varchar(64) so what I'm trying to work out is how to say "if there is one or more space in the input, use their ip", which I have already worked out and is stored in ...

  1. #1

    Default Space detection in text input form

    I am trying to create a "foolproof" login.

    Basically people can type their name in with no password or
    registration, this is done on trust and so that the site can keep track
    of them.
    All the scripts to hold this in place work perfectly however I'm
    struggling with the handling of an input with one or more text.


    The sql type of username is varchar(64) so what I'm trying to work out
    is how to say "if there is one or more space in the input, use their
    ip", which I have already worked out and is stored in $ip

    I've tried
    if ($username == " ") $username = "Mr or Miss ".$ip;

    But submitting my name as a space, or even as   doesn't trigger
    that line and the site knows me as " " (without quotes)

    How come the above line doesn't work, and as a bonus question, how can I
    make it check if there is more than one space (if some cunning git puts
    30 of them for example) and still trigger the above or a similar line?


    TIA
    Chris Guest

  2. #2

    Default Re: Space detection in text input form

    Chris B wrote: 

    RER! (= "Regular Expressions Rock!", just made it up :)

    if (preg_match("/\s/", $username)) ...


    -veikko

    --
    veikko
    mail .com
    makinen
    Veikko Guest

  3. #3

    Default Re: Space detection in text input form

    "Chris B" <co.uk> kirjoitti
    viestissä:42a060fc$0$23699$zen.co.uk... 

    run the input through trim* and see if there are any valid characters left,
    meaning the string still has a non-zero length.

    for example
    if(strlen($username = trim($username)))<1)
    $username = "Mr or Miss ".$ip;

    That way if luser inputs spaces, tabs, whatever that is concidered
    "whitespace", trim will remove them and what's left is then checked. That
    way " John Doe " turns into "John Doe" and " " turn into "",
    which has length less than 1 and thus becomes "Mr or Miss 127.0.0.1".

    *) trim -- Strip whitespace from the beginning and end of a string

    --
    "I am pro death penalty. That way people learn
    their lesson for the next time." -- Britney Spears

    com


    Kimmo Guest

  4. #4

    Default Re: Space detection in text input form

    Kimmo Laine wrote: 

    You missed a ( off, i.e.

    if((strlen($username = trim($username)))<1)
    $username = "Mr or Miss ".$ip;

    But otherwise it works thanks.
    Chris Guest

  5. #5

    Default Re: Space detection in text input form

    "Chris B" <co.uk> kirjoitti
    viestissä:42a07d4c$0$23688$zen.co.uk... 
    >
    > You missed a ( off, i.e.
    >
    > if((strlen($username = trim($username)))<1)
    > $username = "Mr or Miss ".$ip;
    >
    > But otherwise it works thanks.[/ref]

    Answers are free, debugging costs extra :D

    --
    "I am pro death penalty. That way people learn
    their lesson for the next time." -- Britney Spears

    com


    Kimmo Guest

  6. #6

    Default Re: Space detection in text input form


    Kimmo Laine wrote: 
    >
    > Answers are free, debugging costs extra :D[/ref]

    heh!

    maybe the OP can use these :
    //This erase white-spaces on the beginning and the end in each line of
    a string:
    $foldername = preg_replace('~^(\s*)(.*?)(\s*)$~m', "\\2", $foldername);
    //erases all NON-alfanumerics
    $foldername = ereg_replace("[^[:alnum:] ]","",$foldername);
    // take out repetative spaces??:
    $foldername = preg_replace('/\s\s+/', ' ', $foldername);

    --

    juglesh

    juglesh Guest

Similar Threads

  1. form bg color in text input
    By ovydiu in forum Coldfusion - Getting Started
    Replies: 1
    Last Post: September 4th, 02:58 PM
  2. Flash Form Text Input onchange
    By Dan in forum Macromedia ColdFusion
    Replies: 2
    Last Post: August 30th, 02:48 PM
  3. How to pass a form input text value to a javascriptmethod?
    By hypamw in forum Dreamweaver AppDev
    Replies: 0
    Last Post: April 10th, 12:33 AM
  4. Sound Input Detection
    By Magic Benji webforumsuser@macromedia.com in forum Macromedia Director Lingo
    Replies: 1
    Last Post: October 17th, 04:39 AM
  5. Replies: 0
    Last Post: September 27th, 01:46 PM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139