vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Regular Expression Help (https://vborg.vbsupport.ru/showthread.php?t=138763)

0ptima 02-07-2007 10:49 PM

Regular Expression Help
 
I have spammers signing up to my forum and entering the word "Viagra" in one of my custom fields. You can now use pattern matching in custom fields and I need help in creating a regular expression to check the field. I would like the regex to fail if the custom field contains the work Viagra. Hop someone can help.

nico_swd 02-08-2007 10:49 AM

You could do something like this.

PHP Code:

$badwords = array('viagra''++++''+++++++');

if (
preg_match('/('implode('|'array_map('preg_quote'$badwords)) .')/i'$field))
{
    
// Show error
}
else
{
    
// Submit



0ptima 02-08-2007 11:54 PM

I was hoping of something more along the line of
^[0-9]{7,8}$

Here is the blurb for VB's help ...

Regular Expression (Select, Input, Radio, Textarea only)
You may require this field's contents to match a PCRE-type regular expression. For example, you could have a field that is for the user's ICQ number. Since ICQ numbers consist of only numerals, you could write a regular expression to check for non-numerals.

Example: (Do not start or end the expression with an escape character)

^[0-9]{7,8}$

If you want to allow an empty response to be given, you need to account for it within the regex:

^[0-9]{7,8}$|^$

Analogpoint 02-09-2007 04:14 PM

If you only want to block the word 'viagra' you could try this...

This will allow anything other than the word viagra, also allows a blank field
Code:

^viagra$|^$
Do this if you want to disallow if the text *contains* the string viagra.
Code:

^.*viagra.*$|^$

0ptima 02-11-2007 02:47 AM

I tried both regexs and they did not work.

Analogpoint 02-12-2007 02:01 AM

Oops, you're right. The regex I gave you would require you to enter 'viagra' or a blank string. I tested this a bit, and it looks like it works, although it looks so ugly that there must be a better way to do it. I need to brush up on my regexes. Note that this matches any string that contains the string 'viagra'

^[^v]*[^i]*[^a]*[^g]*[^r]*[^a]*$|^$

0ptima 02-12-2007 09:52 PM

Thanks, ill give it a shot.

Analogpoint 02-13-2007 04:57 AM

Let me know if it works for you.


All times are GMT. The time now is 07:05 PM.

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.01002 seconds
  • Memory Usage 1,723KB
  • 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
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)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