Gossamer Forum
Home : Products : Gossamer Links : Discussions :

REGEX to prevent spaces

Quote Reply
REGEX to prevent spaces
I want to force my new users to only use underscores instead of spaces in their username.

What is the regex to prevent spaces between words as well as leading or training spaces?

I thought about using javascript, but this is not the real answer I think.

I would like to see better error reporting capability from Links when a user incorrectly enters data into any of the links forms. Like "The username field must not contain any spaces". Or whatever based on the regex. I know this can easily be done with javascript, but doesnt this limit users or cause potential problems for some browsers?

Thanks guys.


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] REGEX to prevent spaces In reply to
$var =~ /^\s/;

That should tell if there are any spaces in the variable (I think. I'm a bit rusty on Regex and Perl Tongue)

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Ian] REGEX to prevent spaces In reply to
spaces between words as well as leading or training spaces, i.e. all spaces.

s/\s+/_/g;
------------------
Dorg Hurgler Van Schongleur,
NordHein Van Resetelem, Belgium.
Eck SchekeBuugler Technologies.

Last edited by:

searchposts: Jun 3, 2002, 10:34 AM
Quote Reply
Re: [Andy] REGEX to prevent spaces In reply to
$ trailing

^leading

s/(\w+)\s+(\w+)\s/$1_$3/g; word
------------------
Dorg Hurgler Van Schongleur,
NordHein Van Resetelem, Belgium.
Eck SchekeBuugler Technologies.
Quote Reply
Re: [searchposts] REGEX to prevent spaces In reply to
Thanks Andy and Searchposts!

I will try s/\s+/_/g;


You may be rusty Andy, but I am clueless. I have not studied the regex section yet... it looks the most complex!! It is also something you don't really want to get wrong in your links database, or you could be blocking new users from signing up and be unaware of it.. thats why I posted. I will test this out.

Cool


Edit: I should be trying s/(\w+)\s+(\w+)\s/$1_$3/g; shouldn't I ?


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: Jun 3, 2002, 10:39 AM
Quote Reply
Re: [Ian] REGEX to prevent spaces In reply to
I'd do:

$foo = 'P A U L';
$foo =~ y/ /_/;
Quote Reply
Re: [Paul] REGEX to prevent spaces In reply to
So if I stick y/ /_/ into my User table regex for Username that should work?

Thanks for the comment Paul.


Edit: I am so glad bouncy ball is gone! I used his web site as a test for my LSQL banned list Wink


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: Jun 3, 2002, 11:05 AM
Quote Reply
Re: [Ian] REGEX to prevent spaces In reply to
No, sorry I didn't realise you were doing it that way.

You can't do substitutions using the regex field, that is only for matching, so you could only generate an error if someone entered a space, you couldn't substitute it.

For that you'd use:

[^\s]

...in the regex field.

Last edited by:

Paul: Jun 3, 2002, 11:07 AM
Quote Reply
Re: [Paul] REGEX to prevent spaces In reply to
ok i'll try that thanks again!

PS: your question mark has shrunk!


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Paul] REGEX to prevent spaces In reply to
Eeek... when I tried to stick a regex into the Username field of Users I get:

This table already has a primary key.

I know it does... its the Username field I am trying to modify!!!


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] REGEX to prevent spaces In reply to
Paul....get rid of my piccy as your Avatar Wink

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] REGEX to prevent spaces In reply to
Ah, a face to the nameSmile. Very nasty Paul. Where is your pic?


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] REGEX to prevent spaces In reply to
Yeah Paul..if your gonna embarras anyone, put your own piccy up! I know I shouldnt have sent him the test pictures I took with my mini digital camera Frown

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!