vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Need some Regex help (https://vborg.vbsupport.ru/showthread.php?t=313895)

3lou 55 08-24-2014 08:45 AM

Need some Regex help
 
Hello there,

So we were getting annoyed on our forums with stupid registration names.
So we wanna setup a regex now so that they can't do this anymore.
I know that this feature is available in the admin panel and we will also use that.
I just need some help with the regex.

Basicly what we want is we wanna allow these chars a-z A-Z 1234567890 and one space inbetween the name.
The space inbetween the name is not a MUST, but if there are spaces in the name it should only be inside the name, and it should only be one.

If anyone could help me with this one it would be greatly appreciated.

kh99 08-24-2014 09:15 AM

I think this works:
Code:

^[A-Za-z0-9]+\s?[A-Za-z0-9]+$
Here's a page that will allow you to test it: http://www.regexplanet.com/advanced/java/index.html (there are others out there if you google regex test).

3lou 55 08-24-2014 10:45 AM

Quote:

Originally Posted by kh99 (Post 2512532)
I think this works:
Code:

^[A-Za-z0-9]+\s?[A-Za-z0-9]+$
Here's a page that will allow you to test it: http://www.regexplanet.com/advanced/java/index.html (there are others out there if you google regex test).

Yep cheers, that worked!
Thanks alot.

Black Snow 08-27-2014 12:44 PM

Quote:

Originally Posted by 3lou 55 (Post 2512540)
Yep cheers, that worked!
Thanks alot.

I found that some people use seperators more than once in a row so I had to make sure that the first and last character are not separators, and that there's never more than one separator in a row. Here's my way:

/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/

After matching one or more alphanumeric characters, if there's a separator it must be followed by one or more alphanumerics.

3lou 55 09-06-2014 10:22 AM

Quote:

Originally Posted by Black Snow (Post 2512876)
I found that some people use seperators more than once in a row so I had to make sure that the first and last character are not separators, and that there's never more than one separator in a row. Here's my way:

/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/

After matching one or more alphanumeric characters, if there's a separator it must be followed by one or more alphanumerics.

I was just about to post to ask this question, cheers.
Thanks for the great help (y)


All times are GMT. The time now is 08:43 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01086 seconds
  • Memory Usage 1,720KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete