Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
scorpious
Worker
Worker



Joined: Dec 03, 2005
Posts: 153

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

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
hicuxunicorniobestbuildpc
The Mouse Is Extension Of Arm



Joined: Aug 13, 2009
Posts: 1123

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

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







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

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
 
hicuxunicorniobestbuildpc







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

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
 
scorpious







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

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
 
hicuxunicorniobestbuildpc







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

I'm glad you solved it. It was my pleasure to help u. See u around.
 
montego
Site Admin



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

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

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., "_")

_________________
Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

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
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©