Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
want no space in signup name
Old 07-10-2006, 06:03 PM want no space in signup name
one
Experienced Talker

Posts: 44
Trades: 0
i have a sign up forum that i dont want the users to have spaces in their user name.
it will go to an error page if a field is blank.can i add something so it will do the same if the user name has a space?
PHP Code:
if ($_POST['do'] == 'setup')
{
    if (empty(
$_POST['name'])
    {
        
print_error_message($lang['error']);
    } 
one is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-10-2006, 10:48 PM Re: want no space in signup name
Webmaster Talker

Posts: 626
Trades: 0
I'm sure you can manipulate this for what you need...

PHP Code:
<?php
$user1 
"Mighty Mouse";
$user2 "Mighty_Mouse";

if(
eregi("[ \t]"$user1)) {
   echo 
"$user1: contains a space or tab!<br>";
} else {
    echo 
"$user1: Does NOT contain a space or a tab!<br>";
}

if(
eregi("[ \t]"$user2)) {
   echo 
"$user2: contains a space or tab!<br>";
} else {
    echo 
"$user2: Does NOT contain a space or a tab!<br>";
}
?>
jim.thornton is offline
Reply With Quote
View Public Profile
 
Old 07-10-2006, 10:49 PM Re: want no space in signup name
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
Easiest thing to do is to use some regex (you could use just a strpos(), but regex is easily expanded if you want to limit to other chars in the future).

PHP Code:
if ($_POST['do'] == 'setup')
{
    
$_POST['name'] = trim($_POST['name']);

    if (empty(
$_POST['name']) || !preg_match('#^([^ ]+)$#'$_POST['name']))
    {
        
print_error_message($lang['error']);
    } 
Or better yet, just use regex to explicitly set the acceptable chars:
PHP Code:
<?php

if ($_POST['do'] == 'setup')
{
    
$_POST['name'] = trim($_POST['name']);

    if (empty(
$_POST['name']) || !preg_match('#^([a-zA-Z0-9\-_]+)$#'$_POST['name']))
    {
        
print_error_message($lang['error']);
    }
^ Will allow only letters (a-z), numbers, hyphens and underscores.
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to want no space in signup name
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23178 seconds with 12 queries