PHP Web Host - Quality Web Hosting For All PHP Applications Just Great Software
  Login or Register
 • Home • Downloads • Your Account • Forums • 

View next topic
View previous topic


Google
 
Web RavenPHPScripts (This Site)
Post new topic   Reply to topic
Author Message
scorpious
Worker
Worker


Joined: Dec 03, 2005
Posts: 148
Location: West Midlands. United Kingdom

PostPosted: Fri Jan 20, 2012 2:04 pm Reply with quote Back to top

Hi All

I have an input box for members name, it works ok

I have the following code

Code:
 $mnane = preg_replace("/[^a-zA-Z0-9\s]/", "", $mnane);


It work ok, till someone puts a members name in with underscore _ within it, ie. com_thor the code removes the underscore and joins the name together.

I also have a Location input, which is 40 Characters, when we put in a location then use a comma to seperate town name with area ie. birmingham, west midlands it removes the comma.

How can I allow the use of underscore and comma's within the code

Cheers
Scorp
View user's profile Send private message Yahoo Messenger
unicornio
Involved
Involved


Joined: Aug 13, 2009
Posts: 432

PostPosted: Fri Jan 20, 2012 3:02 pm Reply with quote Back to top

I guess if you must use \\ for all your caracters you wanna add to show username with underscore. Try this one.

Code:
$mnane = preg_replace("/[^a-zA-Z0-9_-\\[\\]\\{\\}\\=-]/", "", $mnane);
View user's profile Send private message
scorpious
Worker
Worker


Joined: Dec 03, 2005
Posts: 148
Location: West Midlands. United Kingdom

PostPosted: Fri Jan 20, 2012 5:00 pm Reply with quote Back to top

Hi unicornio

I dont use \\ and the code did not work, however, if I use this code:
Code:
 "/[^a-zA-Z0-9_-\s]/", ""


The underscore works, Its just the commas I need to allow now.

Cheers scorp
View user's profile Send private message Yahoo Messenger
unicornio
Involved
Involved


Joined: Aug 13, 2009
Posts: 432

PostPosted: Fri Jan 20, 2012 5:58 pm Reply with quote Back to top

Code:
    /[a-zA-Z0-9,]+/ matches if any of the characters are alphanumeric + comma.
    /^[a-zA-Z0-9,]+$/ matches if all of the characters are alphanumeric + comma.



Code:
 $mnane = preg_replace("/^[a-zA-Z0-9,]*$/", "", $mnane);


Code:

    / : regex delimiters.
    ^ : start anchor
    [..] : Char class
    0-9 : any digit
    a-z : any alphabet
    , : a comma. comma is not a regex metachar, so you need not escape it
    + : quantifier for one or more. If an empty input is considered valid, change + to *
    $ : end anchor
    i : to make the matching case insensitive.


Try this one and let me know. If it doesn't work then someone else can help u
Shocked
View user's profile Send private message
scorpious
Worker
Worker


Joined: Dec 03, 2005
Posts: 148
Location: West Midlands. United Kingdom

PostPosted: Fri Jan 20, 2012 6:25 pm Reply with quote Back to top

Hi unicornio

I have just added the comma within the code:
Code:
"/[^a-zA-Z0-9,_-\s]/", ""


And now I can use the comma and underscore

The code you shown:
Code:

    / : regex delimiters.
    ^ : start anchor
    [..] : Char class
    0-9 : any digit
    a-z : any alphabet
    , : a comma. comma is not a regex metachar, so you need not escape it
    + : quantifier for one or more. If an empty input is considered valid, change + to *
    $ : end anchor
    i : to make the matching case insensitive.


I have been looking around the net for a explanation to preg_replace and the breakdown of it, that code explains, nice one

Cheers Scorp
View user's profile Send private message Yahoo Messenger
unicornio
Involved
Involved


Joined: Aug 13, 2009
Posts: 432

PostPosted: Fri Jan 20, 2012 7:07 pm Reply with quote Back to top

I'm glad you solved it. It was my pleasure to help u. See u around.
View user's profile Send private message
montego
Site Admin


Joined: Aug 29, 2004
Posts: 9136
Location: Arizona

PostPosted: Sat Jan 21, 2012 9:03 am Reply with quote Back to top

RN 2.5.0 uses the following instead (takes Unicode into account):

/[^\p{L}\p{N}\p{Pd}\p{Pc}]/

This translates to:

Any Letter
Any Number
Any dash separator (e.g., "-")
Any connector (e.g., "_")
View user's profile Send private message Visit poster's website
Display posts from previous:       
Post new topic   Reply to topic

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Forums ©
 

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2002-2011 by Raven

You can syndicate our news using the file xml

CSE HTML Validator Helped Clean up This Page! [Valid RSS] valid RSS 2.0 Valid robots.txt Stop Spam Harvesters, Join Project Honey Pot

Website engines core code is © copyright by PHP-Nuke but has been heavily patched and modified by myself and others.
PHP-Nuke is a free software released under the GNU/GPL.


:: fisubice phpbb2 style by Daz :: PHP-Nuke theme by www.nukemods.com ::
:: fisubice Theme Modified by the RavenNuke™ Team ::

:: W3C CSS Compliance Validation :: W3C HTML 4.01 Transitional Compliance Validation ::

zerosum