Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: form validation

  1. #1
    New Coder
    Join Date
    Sep 2005
    Posts
    89
    Thanks
    2
    Thanked 0 Times in 0 Posts

    form validation

    Hello all - probably a simple one, but not for me!

    I'm trying to check if a variable from a form has any spaces in it. I don't want to strip out the whitespace (as its a username and password), but display a warning.

    Heres what I have so far:

    if( !eregi("^[a-z0-9]+)*",
    $_POST ['nickname'])){
    readfile("blankfields.html");
    exit;
    } else {
    }

    Any suggestions?

    Thanks

  • #2
    Regular Coder
    Join Date
    Jan 2006
    Location
    Preston, Lancashire, England
    Posts
    285
    Thanks
    0
    Thanked 0 Times in 0 Posts
    simplest way would be this
    PHP Code:
    $username str_replace(" """,$_POST['nickname']) 

  • #3
    New Coder
    Join Date
    Sep 2005
    Posts
    89
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by MRMAN
    simplest way would be this
    PHP Code:
    $username str_replace(" """,$_POST['nickname']) 
    Thanks MRMAN.

    I actually can't strip out the gaps, as its going to be the users name and password. If i strip it out, then their log in will be different. (for example: the user inputs 'player 1', and the application saves it as 'player1')

    I have put a notice on the form asking users not to add spaces but they are not reading it. So I need to check it and issue a warning if there is a space.

  • #4
    New Coder
    Join Date
    Sep 2005
    Posts
    89
    Thanks
    2
    Thanked 0 Times in 0 Posts
    actually I just got a fix for it.

    If anyone is interested:

    if ( substr_count ($string, " ") > 0 ) {

    // We have spaces

    } else {

    // We don't

    }


    Thanks

  • #5
    Regular Coder trib4lmaniac's Avatar
    Join Date
    Feb 2004
    Location
    Cornwall, UK
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You'll usually find that sitepoint gets your answers to your questions a little quicker than around here.
    Although I'm happy to answer your questions anywhere


  •  

    Posting Permissions

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