FAQ | Search | Memberlist | Usergroups | Register | Profile | Inbox | Log in | SmartFeedSmartFeed


 okgg.org > Forum Index > All Things Technical > Need regular expression help!

  Author    Thread Post new topic  Reply to topic
Shinare
SEXNOCULAR


Joined: 17 Mar 2004
Posts: 13332
Location: Up your butt with a coconut!!
Need regular expression help!  Reply with quote  

I need to validate a field in a form entry from a website in vb on the back end and I'm trying to use a regular expression. I want to make sure that only letters, numbers and commas are used in the text box. I use:

Code


<%@ Import Namespace="System.Text.RegularExpressions" %>

...

<script language="VB" runat="server">
        Sub btnSearch_OnClick(ByVal sender As Object, ByVal e As EventArgs)

...
Dim pattern as String = "[\,\w]"
strSearch = txtSearch.Text
Dim SearchStringMatch As Match = Regex.Match(strSearch, pattern)

...

      If Not SearchStringMatch.Success Then
         Label1.Text = "Invalid Characters found in search string."
         Exit Sub
      End If

...


For some reason its saying ANYTHING I type in is valid, no matter what characters I use. Sad

I'm not very good at this regular expression stuff, anyone has help for me?
_________________
For with what measure you measure it will be measured to you.

Post Fri Oct 28, 2011 5:12 pm  View user's profile Send private message ICQ Number
Menos
Broke My Labia


Joined: 06 Jun 2003
Posts: 1125
Location: Oklahoma City
 Reply with quote  

I hate regex. Mostly because I'm no good at it Smile But, I'm thinking your pattern will match if there is ANY character that matches. So if you had the string B*tch it would match success on the 'B' and be done.

Post Fri Oct 28, 2011 7:23 pm  View user's profile Send private message Send e-mail
Sevnn
Candy Cane King


Joined: 22 Mar 2003
Posts: 7711
Location: Kyrat
 Reply with quote  

Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.


Change your regex expression to this: ^[a-zA-Z0-9,]+$

Post Fri Oct 28, 2011 11:20 pm  View user's profile Send private message Send e-mail AIM Address ICQ Number
Shinare
SEXNOCULAR


Joined: 17 Mar 2004
Posts: 13332
Location: Up your butt with a coconut!!
 Reply with quote  

Sevnn wrote:
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.


Change your regex expression to this: ^[a-zA-Z0-9,]+$


LOL your quote is so true.. hehe I'm going to have to remember that! Thanks Sevnn, I'll give that a try on Monday. Smile
_________________
For with what measure you measure it will be measured to you.

Post Sun Oct 30, 2011 8:54 pm  View user's profile Send private message ICQ Number
Brules
M F C E O


Joined: 23 Mar 2003
Posts: 11074
Location: Konnichiwa, bitches.
 Reply with quote  


_________________
K-SWISS Power cologne. Who knew you could bottle the scent of boner?

Post Sun Oct 30, 2011 8:55 pm  View user's profile Send private message Send e-mail
Drix
SEAT #ASS 10


Joined: 18 Aug 2004
Posts: 1773
Location: Norman
 Reply with quote  

Brules wrote: "be different be yourself express yourself

...learn to use a fucking comma?? Twisted Evil
_________________
Advocating the end of the world since July 1995.

Post Mon Oct 31, 2011 4:06 am  View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number
Brules
M F C E O


Joined: 23 Mar 2003
Posts: 11074
Location: Konnichiwa, bitches.
 Reply with quote  

Your sand is getting crusty.....


_________________
K-SWISS Power cologne. Who knew you could bottle the scent of boner?

Post Mon Oct 31, 2011 8:28 am  View user's profile Send private message Send e-mail
Shinare
SEXNOCULAR


Joined: 17 Mar 2004
Posts: 13332
Location: Up your butt with a coconut!!
 Reply with quote  

That expression worked Sevnn! Thanks, I forgot to mention I needed spaces as well so I just added "\s" after the comma and that seems to have done the trick! Muchos Grassy-ass! Smile
_________________
For with what measure you measure it will be measured to you.

Post Mon Oct 31, 2011 9:40 am  View user's profile Send private message ICQ Number
Brules
M F C E O


Joined: 23 Mar 2003
Posts: 11074
Location: Konnichiwa, bitches.
 Reply with quote  

Glad I could help Shinare! Smile
_________________
K-SWISS Power cologne. Who knew you could bottle the scent of boner?

Post Mon Oct 31, 2011 11:10 am  View user's profile Send private message Send e-mail
Sevnn
Candy Cane King


Joined: 22 Mar 2003
Posts: 7711
Location: Kyrat
 Reply with quote  

Glad it helped Shinare.

Post Tue Nov 01, 2011 12:05 am  View user's profile Send private message Send e-mail AIM Address ICQ Number
  Display posts from previous:      
Post new topic  Reply to topic

Last Thread | Next Thread  >

Quick Reply

  
Jump to:  
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum