473,320 Members | 2,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Need a regex to check form submission url format

I want a simple as possible regex to check the format of my form submission URL string, I don't care whether is an actual real working URL, just that it be in proper URL format and, IF POSSIBLE add someting so that the URL characters are the only charactrers entered in the field:
so it would be an err msg prompt for legit users to enter their link in the proper format;
On the uther hand, it should not allow spammers to enter tons of text in the url field.
I have used the following regex to chewck that there are characters supplied in addition to the http:// value in the form field, and it works with simple urls but it does not work with urls such as
http://somesubdomain-somesitename.org/somepagename.htm
if ($FORM{'url'} eq 'http://' || $FORM{'url'} !~ /^(f|ht)tp:\/\/\w+\.\w+/) {
&no_url;
}
Nov 13 '08 #1
2 3651
KevinADC
4,059 Expert 2GB
There are a number of URI checking modules on CPAN, but if you don't want to go the module route, you can use this regexp taken from the URI modules documentation:

Expand|Select|Wrap|Line Numbers
  1. my $uri = 'http://www.mysite.com:8080/path/index.html?test=foo&foo=bar#internal-link';
  2.  
  3. my($scheme, $authority, $path, $query, $fragment) =
  4.   $uri =~ m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?|;
  5.  
  6. print qq{scheme = $scheme
  7. authority = $authority
  8. path = $path
  9. query = $query
  10. fragment = $fragment};
  11.  
Then you apply tests to each part of the URI individually.
Nov 13 '08 #2
Thx for the response.
This reply delayed as I had to go out of town.
My thought was that what I really need to do is check for basic url format in the form submissions.
As any valid url format has to be OK, then, manual editing or other spam checks in the script is the spam solution, as just checking for basic url formating is the key here.

I came up with if string != (http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?) {
& check url;
}
which works for simple urls, but I'd like to add code for more complex urls such as http://subdomain.somedomain.com/somefilename.htmlor
http://xyzabd-somedomain.com/somefilename.html
or
Seems simple (to me) but not able to to get the script to process - it hangs on the url field data.
thx,
Mike
Nov 17 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: AnnMarie | last post by:
My JavaScript Form Validation doesn't work at all in Netscape, but it works fine in IE. I made some of the suggested changes which enabled it to work in IE. I couldn't make all the changes...
6
by: Vishant | last post by:
Hi, I'm new to javascript and regEx and trying to solve the following problem. I have a function which validates the password if there is a number:...
5
by: J. J. Cale | last post by:
Little astrology program has 2 text input boxes for birth dates. There are 3 selects for day month year that will supply output to whichever text input had the focus last. If the user picks from...
2
by: Mike Button | last post by:
Hello all, I am really really desperate on what I should do, and I am asking for help from anyone in this newsgroup, here's the situation: I am creating a form that is being run on a server...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
6
by: Ouch! | last post by:
I am using Regular Expressions and Javascript to validate a form, specifically I want to make sure that if they try to upload a file that it has a proper name w/ certain extensions (doc,pdf, rtf). ...
8
mmarif4u
by: mmarif4u | last post by:
Hi everybody... I want to enter values to db like the following,,, Format is like this (810605-14-6356) This is the rite format, No a to z letters... 6 digits then - then 2 digits then - then 4...
15
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
3
by: William Gill | last post by:
I am not to sharp on my regular expressions because I haven't used them in quite a while. So I am relearning regex and the PHP regex functions at the same time. Which means when I screw up, I'm...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.