Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

how to prevent urls in contact forms

Last post 06-12-2008, 7:13 PM by Aussie Susan. 1 replies.
Sort Posts: Previous Next
  •  06-12-2008, 4:43 AM 43088

    how to prevent urls in contact forms

    Hello I am new to this but eagerly learning. I am having a problem with my contact form where I get spammed with urls where there is a text box or text field in my form.

    I was told that I need to reverse for this:

    if(!regex == ^[a-zA-Z0-9\-\.]+\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU)$)

    A full sample would be helpful, I have no clue what this means! 

  •  06-12-2008, 7:13 PM 43114 in reply to 43088

    Re: how to prevent urls in contact forms

    I realise that this is in a different part of the forum, but there are posting guidelines at http://regexadvice.com/forums/thread/41315.aspx which tell you the type of information we need so that we can help you properly.

    I'm not sure what you are really asking, but there are some simple suggesitons I can make.

    Firstly, if you have a regex that matches some text, then code of the form (pseudo-code):

    if( regex.matches(pattern, options, text)
    {
        -- do something if the regex pattern matches the text
    }

    then you can reverse the logic with:

    if( not regex.matches(pattern, options, text)
    {
        -- do something if the regex pattern does not match the text
    }

    Please be aware that it is not possible to match a URL with  regex pattern 100% of the time - one of the regular guru's here (mash) has given accuracies of 50% at most. For example, the pattern you have provided matches any string of characters made up of alphanumeric characters, a full stop and a dash that ends in one of the common domain names. However, a valid URL might be

    abc.def.com/

    and this would not match and yot may well cause the same problem as

    abc.def.com

    which would be matched.

    My experience is that validations are often better approached from the 'what do we allow' than from 'what don't we allow' - the former is nearly always more restrictive and therefore often closer to the real (but unstated) need.

    Susan
     

View as RSS news feed in XML