Joined: 17 Mar 2004
Posts: 13332
Location: Up your butt with a coconut!!
Need regular expression help!
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:
<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.
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.
Fri Oct 28, 2011 5:12 pm
Menos
Broke My Labia
Joined: 06 Jun 2003
Posts: 1125
Location: Oklahoma City
I hate regex. Mostly because I'm no good at it 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.
Fri Oct 28, 2011 7:23 pm
Sevnn
Candy Cane King
Joined: 22 Mar 2003
Posts: 7711
Location: Kyrat
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,]+$
Fri Oct 28, 2011 11:20 pm
Shinare
SEXNOCULAR
Joined: 17 Mar 2004
Posts: 13332
Location: Up your butt with a coconut!!
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. _________________ For with what measure you measure it will be measured to you.
Sun Oct 30, 2011 8:54 pm
Brules
M F C E O
Joined: 23 Mar 2003
Posts: 11074
Location: Konnichiwa, bitches.
_________________ K-SWISS Power cologne. Who knew you could bottle the scent of boner?
Sun Oct 30, 2011 8:55 pm
Drix
SEAT #ASS 10
Joined: 18 Aug 2004
Posts: 1773
Location: Norman
Brules wrote: "be different be yourself express yourself
...learn to use a fucking comma?? _________________ Advocating the end of the world since July 1995.
Mon Oct 31, 2011 4:06 am
Brules
M F C E O
Joined: 23 Mar 2003
Posts: 11074
Location: Konnichiwa, bitches.
Your sand is getting crusty.....
_________________ K-SWISS Power cologne. Who knew you could bottle the scent of boner?
Mon Oct 31, 2011 8:28 am
Shinare
SEXNOCULAR
Joined: 17 Mar 2004
Posts: 13332
Location: Up your butt with a coconut!!
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! _________________ For with what measure you measure it will be measured to you.
Mon Oct 31, 2011 9:40 am
Brules
M F C E O
Joined: 23 Mar 2003
Posts: 11074
Location: Konnichiwa, bitches.
Glad I could help Shinare! _________________ K-SWISS Power cologne. Who knew you could bottle the scent of boner?
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