allowing hyphens in blog names

I am able to add hyphens when I create a new blog from the admin, but I notice this can not be done when someone signs up, same is true with capital letters. Not so concerned about the capital letters, but is there a simple solution to allow new signups the option to use hyphens in their blog name?

thanks for any input.
Tony V

  • TonyV
    • Site Builder, Child of Zeus

    Thanks Andrew,
    looks like a basket of words to me. I have this;

    if ( empty( $user_name ) )
    $errors->add('user_name', __("Please enter a username"));

    $maybe = array();
    preg_match( "/[a-z0-9]+/", $user_name, $maybe );

    if( $user_name != $maybe[0] ) {
    $errors->add('user_name', __("Only lowercase letters and numbers allowed"));
    }

    $illegal_names = get_site_option( "illegal_names" );
    if( is_array( $illegal_names ) == false ) {
    $illegal_names = array( "www", "web", "root", "admin", "main", "invite", "administrator" );
    add_site_option( "illegal_names", $illegal_names );
    }
    if( in_array( $user_name, $illegal_names ) == true ) {
    $errors->add('user_name', __("That username is not allowed"));
    }

    if( is_email_address_unsafe( $user_email ) )
    $errors->add('user_email', __("You cannot use that email address to signup. We are having problems with them blocking some of our email. Please use another email provider."));

    if( strlen( $user_name ) < 4 ) {
    $errors->add('user_name', __("Username must be at least 4 characters"));
    }

    if ( strpos( " " . $user_name, "_" ) != false )
    $errors->add('user_name', __("Sorry, usernames may not contain the character '_'!"));

    // all numeric?
    $match = array();
    preg_match( '/[0-9]*/', $user_name, $match );
    if ( $match[0] == $user_name )
    $errors->add('user_name', __("Sorry, usernames must have letters too!"));

    if ( !is_email( $user_email ) )
    $errors->add('user_email', __("Please enter a correct email address"));

    if ( !validate_email( $user_email ) )
    $errors->add('user_email', __("Please check your email address."));

    $limited_email_domains = get_site_option( 'limited_email_domains' );
    if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) {
    $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
    if( in_array( $emaildomain, $limited_email_domains ) == false ) {
    $errors->add('user_email', __("Sorry, that email address is not allowed!"));
    }
    }

    // Check if the username has been used already.
    if ( username_exists($user_name) )
    $errors->add('user_name', __("Sorry, that username already exists!"));

    // Check if the email address has been used already.
    if ( email_exists($user_email) )
    $errors->add('user_email', __("Sorry, that email address is already used!"));

    can you give me a hint which I should edit to allow for hyphen only, not under scores just -

    thanks for any help.

    Tony V

  • Andrew
    • Champion of Loops

    Oops, I actually gave you the wrong lines. For the blog names the lines are 989-1040.

    You would need to modify this bit(ln 1000):
    preg_match( "/[a-z0-9]+/", $blogname, $maybe );

    Unfortunately that's regular expression fun which I *really* don't care for. You'll need to do a google search to read up on it a bit.

    Thanks,
    Andrew

  • TonyV
    • Site Builder, Child of Zeus

    in case someone finds this I should point out all I did was add the hyphen after the 9 so on line 1000 instead of;

    preg_match( "/[a-z0-9]+/", $blogname, $maybe );
    if( $blogname != $maybe[0] ) {

    I got

    preg_match( "/[a-z0-9-]+/", $blogname, $maybe );
    if( $blogname != $maybe[0] ) {

    works great :slight_smile:

    Tony V

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.