phpBB2Refugees.com Logo
Not affiliated with or endorsed by the phpBB Group

Register •  Login 

Continue the legacy...

Welcome to all phpBB2 Refugees!Wave Smilie

This site is intended to continue support for the legacy 2.x line of the phpBB2 bulletin board package. If you are a fan of phpBB2, please, by all means register, post, and help us out by offering your suggestions. We are primarily a community and support network. Our secondary goal is to provide a phpBB2 MOD Author and Styles area.

Disallow special characters in location profile field.


 
Search this topic... | Search MOD Requests... | Search Box
Register or Login to Post    Index » MOD Requests  Previous TopicPrint TopicNext Topic
Author Message
dogs and things
Board Member



Joined: 18 Nov 2008

Posts: 621
Location: Spain


flag
PostPosted: Tue Sep 21, 2010 8:10 pm 
Post subject: Disallow special characters in location profile field.

Hello again,

I have made the location field mandatory on registration.

I would like users to fill it out using only letters.

I'm trying to find the way to disable numbers and others odd characters.

I have the following code to achieve this:
Code:
// -- Begin MOD Invalid Characters in Location -------------------
    if (preg_match('/^[0-9\.\:\?\¿\¡\!\~\*\$\%\@]+$/', $location))
    {
        $error = true;
        $error_msg = $lang['Location_invalidchr'];
    }
// -- End MOD Invalid Characters on Register ----------------------


I tried inserting this snippet in various locations in usercp_register.php, one of the places I tried is just before:
Code:
       $user_timezone = ( isset($HTTP_POST_VARS['timezone']) ) ? doubleval($HTTP_POST_VARS['timezone']) : $board_config['board_timezone'];


However, this doesn´t do anything, I'm still able to register with f.i. 123456 as my location.

Is the snippet okay, should it work, where would it have to be placed. any other suggestions?

Greetings.

**EDIT**
Problem solved, the above does work, I was editing a local file thinking it was the server file. icon_redface.gif icon_mrgreen.gif

_________________
phpBB2 will never die, I hope!
Back to top
dogs and things
Board Member



Joined: 18 Nov 2008

Posts: 621
Location: Spain


flag
PostPosted: Wed Sep 22, 2010 8:28 am 
Post subject: Re: Disallow special characters in location profile field.

Just a follow-up,

I noticed the code posted above did not work for a location string with several number blocks, 123456 was blocked, but 123 456 was allowed thruogh.

It also didn't take into account excessive CAPS.

I managed to write a snippet that does filter out multiple number blocks and excessive use of CAPS. If a location contains numbers or more than one CAP in a word the following snippet blocks it:

Code:
// -- Begin MOD Invalid Characters in Location -------------------
    $location_parts=explode(' ',$location);
    foreach($location_parts as $wordnum => $loc_parts)
   if (preg_match('/^[0-9\?\¿\¡\!\~\*\$\%\@]+$/', $loc_parts))
    {
        $error = true;
        $error_msg = $lang['Location_invalidchr'];
    }
    if (strtolower(substr($loc_parts,1)) != substr($loc_parts,1) )
    {
        $error = true;
        $error_msg = $lang['Location_capitals'];
    }

// -- End MOD Invalid Characters in Location -------------------


If you want to use this make sure you create the corresponding lang entries in your lang_main.php.

Greetings.

_________________
phpBB2 will never die, I hope!
Back to top
Display posts from previous:   
Register or Login to Post    Index » MOD Requests  Previous TopicPrint TopicNext Topic
Page 1 of 1 All times are GMT
 
Jump to:  

Index • About • FAQ • Rules • Privacy • Search •  Register •  Login 
Not affiliated with or endorsed by the phpBB Group
Powered by phpBB2 © phpBB Group
Generated in 0.0278 seconds using 15 queries. (SQL 0.0021 Parse 0.0008 Other 0.0249)
phpBB Customizations by the phpBBDoctor.com
Template Design by DeLFlo and MomentsOfLight.com Moments of Light Logo