Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 23rd, 2012, 11:19 AM
STLbhoy STLbhoy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 27 STLbhoy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 56 m 13 sec
Reputation Power: 0
Allowing a slash in a form for half address

Hey everyone,

I need to allow half addresses in a form, but need to make sure to limit the use of slashes for injection reasons. The current regex (java) for my address field is:

Code:
^[\\\wá-úÁ-Úà-ùÀ-Ù_\\\-~'\\\.#]+(\\\s[\\\wá-úÁ-Úà-ùÀ-Ù_\\\-~'\\\.#]+)*$ 


What I was thinking about changing it to is:

Code:
^[\\\wá-úÁ-Úà-ùÀ-Ù_\\\-~'\\\.#(\\\d\\\/\\\d)]+(\\\s[\\\wá-úÁ-Úà-ùÀ-Ù_\\\-~'\\\.#(\\\d\\\/\\\d)]+)*$ 


I'm not very experienced with regular expressions and was wondering if someone who is would be willing to comment if there's a better way to accomplish this or if this is ok.

Reply With Quote
  #2  
Old August 23rd, 2012, 11:51 AM
STLbhoy STLbhoy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 27 STLbhoy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 56 m 13 sec
Reputation Power: 0
Update: I tried testing that out but unfortunately it won't do. While it allows for slashes, it allows them in places that it shouldn't, such as 666 Candy/and Drive

Stuck just now so any help would be greatly appreciated.

Reply With Quote
  #3  
Old August 23rd, 2012, 02:49 PM
Jacques1's Avatar
Jacques1 Jacques1 is online now
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,874 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 2 h 59 m 13 sec
Reputation Power: 813
Hi,

You're using the character class [...] wrong. It can only be used for single characters (hence the name), not for complete expressions. So the expression "(\d/\d)" will be interpreted as the sequence of "(", "\d", "/", "\d" again and ")".

But I think this is going in the wrong direction, anyway. Never try to filter "dangerous" characters. Instead, use the appropriate escaping function.

This reminds me of a joke about a bank, which had a webform saying something like: Your username mustn't contain the words "DROP", "ALTER" etc.

Apart from that, your pattern á-úÁ-Úà-ùÀ-Ù looks kind of random to me. What is this good for? I mean, there are obviously more "foreign characters" than this.

Reply With Quote
  #4  
Old August 23rd, 2012, 02:58 PM
STLbhoy STLbhoy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 27 STLbhoy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 56 m 13 sec
Reputation Power: 0
Quote:
Originally Posted by Jacques1
Hi,

You're using the character class [...] wrong. It can only be used for single characters (hence the name), not for complete expressions. So the expression "(\d/\d)" will be interpreted as the sequence of "(", "\d", "/", "\d" again and ")".

But I think this is going in the wrong direction, anyway. Never try to filter "dangerous" characters. Instead, use the appropriate escaping function.

This reminds me of a joke about a bank, which had a webform saying something like: Your username mustn't contain the words "DROP", "ALTER" etc.

Apart from that, your pattern á-úÁ-Úà-ùÀ-Ù looks kind of random to me. What is this good for? I mean, there are obviously more "foreign characters" than this.


I'm actually just working on someone else's code and trying to add the ability to use a slash. The webteam where I work has had so much turnover that there isn't anyone here who worked on the site originally, so I'm hesitant to delve into the back-end java. This regex is actually just defined in a .properties file so I figured it would be easier to just modify it to allow slashes as long as it's in the form "digit slash digit" so that's what I'm going for.

Reply With Quote
  #5  
Old August 23rd, 2012, 03:51 PM
Jacques1's Avatar
Jacques1 Jacques1 is online now
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,874 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 2 h 59 m 13 sec
Reputation Power: 813
OK, I see.

But which kind of "injection" do you want to prevent with restricting the slashes?

If there's no security reason for this, I'd just stuff the slash into the character classes. This pattern is nonsense, anyway. For example, I may type in "________", but I'm not allowed to type in "Some street 123" (because of the double space).

Well, if you still insist on your pattern, you could implement it with:
Code:
^(\\\d+/\\\d+|[\\\wá-úÁ-Úà-ùÀ-Ù_\\\-~'\\\.#]+)(\\\s[\\\wá-úÁ-Úà-ùÀ-Ù_\\\-~'\\\.#]+)*$ 

But be aware that I just corrected your example, if have no idea if this is what you're supposed to do.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Allowing a slash in a form for half address

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap