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
/[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.
/ : 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
Joined: Dec 03, 2005 Posts: 148 Location: West Midlands. United Kingdom
Posted:
Fri Jan 20, 2012 6:25 pm
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
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