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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2008
    Posts
    104
    Thanks
    71
    Thanked 0 Times in 0 Posts

    Arrow Check for spaces in string

    I have a form where a user can enter their first and last name.

    I want to allow spaces, but if a user just enters spaces and nothing else, then it should be considered invalid.

    For example:

    Valid first name = Ann Marie

    Invalid first name = space space

    I tried the empty() function but it still doesn't work.

    Thanks!

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    I want to allow spaces, but if a user just enters spaces and nothing else, then it should be considered invalid.
    PHP Code:
    $var=trim($var);
    if(empty(
    $var)){
    //invalid

    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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