#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    65
    Rep Power
    15
    I have a simple little form that takes the name and a comment, and adds it to a table. I want to know if there is a way to prevent someone from just entering spaces, and having that get entered as their name. I have the if statement check for $name == '' - but the names entered as just spaces get by it. Any ideas?

    Thanks,
    Ben
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4476
    You can try the following:

    $temp = str_replace(" ","",$your_string);
    if (strlen($temp) == 0)
    {
    echo "Choose another name, you entered all spaces.";
    }

    If you want to remove spaces completely, you can use:

    $your_string = str_replace(" ","",$your_string);

    Hope that helps.

    ---John Holmes...
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    65
    Rep Power
    15
    Thanks, that worked perfectly.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    35
    Rep Power
    14
    Why not use JaveScripts to trim user's input:

    <script language="JavaScript"><!--
    function KillSpace(x){
    while((x.length>0) && (x.charAt(0)==' '))
    x = x.substring(1,x.length)
    while((x.length>0) && (x.charAt(x.length-1)==' '))
    x = x.substring(0,x.length-1)
    return x
    }

    function CheckForm()
    {
    document.LogForm.UserName.value=KillSpace(document.LogForm.UserName.value);
    if(document.LogForm.UserName.value.length == 0)
    {
    alert('ninput your name!')
    return false
    }

    document.LogForm.commets.value=KillSpace(document.LogForm.commets.value);
    if(document.LogForm.commets.value.length == 0)
    {
    alert('ninput your commets!')
    return false
    }
    return true
    }
    // --></script>

    in the server side, you can use trim() function.

    $input=trim($input);
    if ( $input == "" ) {
    echo "input please!";
    } else {
    do_process();
    }

    [This message has been edited by xiaoguiwxd (edited October 02, 2000).]

Similar Threads

  1. how to export spaces in CHAR fields ?
    By rab in forum MySQL Help
    Replies: 0
    Last Post: January 28th, 2004, 06:51 AM
  2. Replies: 1
    Last Post: November 24th, 2003, 06:46 PM
  3. error at stopping the server
    By dhanashree in forum Java Help
    Replies: 0
    Last Post: November 21st, 2003, 07:43 AM
  4. how to retrieve values of passed parameters to a method
    By mzkhanis in forum Perl Programming
    Replies: 1
    Last Post: October 1st, 2003, 10:18 AM
  5. submit variables to fields with spaces in the name
    By lukemcd in forum PHP Development
    Replies: 3
    Last Post: September 10th, 2002, 10:21 PM

IMN logo majestic logo threadwatch logo seochat tools logo