473,666 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regular Expression Weirdness

If I have a regexvalidator in a webform with a validation expression of
^[+]?[0-9]\d* and I put the text 2d in a text box being validated by this
validator, the validator fires.

This regex is a simple one that only allows the user to enter integer
values.

However, if I do this on the server side like this

Regex rx = new Regex(@"^[+]?[0-9]\d*");
Match mt = rx.Match("2d");

I get success!!!! why?? is there an option I should be setting?
Nov 18 '05 #1
5 1081
I think the regularexpressi onvalidator automatically puts ^ at the start and
$ at the end...2d DOES match ^[+]?[0-9]\d* but it DOES NOT match
^[+]?[0-9]\d*$ (note the extra $ at the end). That's the difference
between the two.

Also, [0-9]\d* can be rewritten as \d+

Karl

"George Durzi" <gd****@hotmail .com> wrote in message
news:%2******** **********@tk2m sftngp13.phx.gb l...
If I have a regexvalidator in a webform with a validation expression of
^[+]?[0-9]\d* and I put the text 2d in a text box being validated by this
validator, the validator fires.

This regex is a simple one that only allows the user to enter integer
values.

However, if I do this on the server side like this

Regex rx = new Regex(@"^[+]?[0-9]\d*");
Match mt = rx.Match("2d");

I get success!!!! why?? is there an option I should be setting?

Nov 18 '05 #2
Karl,
Thank you again, that worked perfectly.

And thanks for the regex refining tip :)

"Karl" <none> wrote in message news:OO******** ******@tk2msftn gp13.phx.gbl...
I think the regularexpressi onvalidator automatically puts ^ at the start and $ at the end...2d DOES match ^[+]?[0-9]\d* but it DOES NOT match
^[+]?[0-9]\d*$ (note the extra $ at the end). That's the difference
between the two.

Also, [0-9]\d* can be rewritten as \d+

Karl

"George Durzi" <gd****@hotmail .com> wrote in message
news:%2******** **********@tk2m sftngp13.phx.gb l...
If I have a regexvalidator in a webform with a validation expression of
^[+]?[0-9]\d* and I put the text 2d in a text box being validated by this validator, the validator fires.

This regex is a simple one that only allows the user to enter integer
values.

However, if I do this on the server side like this

Regex rx = new Regex(@"^[+]?[0-9]\d*");
Match mt = rx.Match("2d");

I get success!!!! why?? is there an option I should be setting?


Nov 18 '05 #3
George,

Glad you got it working. (Good eyes Karl!)

Just a note: You could also use a CompareValidato r instead of the
RegularExpressi onValidator. If you leave the CompareValidato r's
ControlToCompar e property blank and set it's Operator property to
DataTypeCheck you may then set it's Type property to check if a value
entered is a String, Integer, Double, Date, or Currency.

While I love that I can do almost anything with the regular expression
validator I find simple data type checks much easier to set up with the
CompareValidato r.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"George Durzi" <gd****@hotmail .com> wrote in message
news:uJ******** *****@TK2MSFTNG P10.phx.gbl...
Karl,
Thank you again, that worked perfectly.

And thanks for the regex refining tip :)

"Karl" <none> wrote in message
news:OO******** ******@tk2msftn gp13.phx.gbl...
I think the regularexpressi onvalidator automatically puts ^ at the start

and
$ at the end...2d DOES match ^[+]?[0-9]\d* but it DOES NOT match
^[+]?[0-9]\d*$ (note the extra $ at the end). That's the difference
between the two.

Also, [0-9]\d* can be rewritten as \d+

Karl

"George Durzi" <gd****@hotmail .com> wrote in message
news:%2******** **********@tk2m sftngp13.phx.gb l...
> If I have a regexvalidator in a webform with a validation expression of
> ^[+]?[0-9]\d* and I put the text 2d in a text box being validated by this > validator, the validator fires.
>
> This regex is a simple one that only allows the user to enter integer
> values.
>
> However, if I do this on the server side like this
>
> Regex rx = new Regex(@"^[+]?[0-9]\d*");
> Match mt = rx.Match("2d");
>
> I get success!!!! why?? is there an option I should be setting?
>
>



Nov 18 '05 #4
That is a great tip!!! Thank you much! The regularexpressi onvalidators do
seem like a little overkill for simple type checks

"S. Justin Gengo" <sjgengo@aboutf ortunate[no-spam].com> wrote in message
news:10******** *****@corp.supe rnews.com...
George,

Glad you got it working. (Good eyes Karl!)

Just a note: You could also use a CompareValidato r instead of the
RegularExpressi onValidator. If you leave the CompareValidato r's
ControlToCompar e property blank and set it's Operator property to
DataTypeCheck you may then set it's Type property to check if a value
entered is a String, Integer, Double, Date, or Currency.

While I love that I can do almost anything with the regular expression
validator I find simple data type checks much easier to set up with the
CompareValidato r.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"George Durzi" <gd****@hotmail .com> wrote in message
news:uJ******** *****@TK2MSFTNG P10.phx.gbl...
Karl,
Thank you again, that worked perfectly.

And thanks for the regex refining tip :)

"Karl" <none> wrote in message
news:OO******** ******@tk2msftn gp13.phx.gbl...
I think the regularexpressi onvalidator automatically puts ^ at the start
and
$ at the end...2d DOES match ^[+]?[0-9]\d* but it DOES NOT match
^[+]?[0-9]\d*$ (note the extra $ at the end). That's the difference
between the two.

Also, [0-9]\d* can be rewritten as \d+

Karl

"George Durzi" <gd****@hotmail .com> wrote in message
news:%2******** **********@tk2m sftngp13.phx.gb l...
> If I have a regexvalidator in a webform with a validation expression

of > ^[+]?[0-9]\d* and I put the text 2d in a text box being validated by

this
> validator, the validator fires.
>
> This regex is a simple one that only allows the user to enter integer
> values.
>
> However, if I do this on the server side like this
>
> Regex rx = new Regex(@"^[+]?[0-9]\d*");
> Match mt = rx.Match("2d");
>
> I get success!!!! why?? is there an option I should be setting?
>
>



Nov 18 '05 #5
George,

You're welcome. Thanks for the praise. :-)

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"George Durzi" <gd****@hotmail .com> wrote in message
news:Om******** ******@TK2MSFTN GP10.phx.gbl...
That is a great tip!!! Thank you much! The regularexpressi onvalidators do
seem like a little overkill for simple type checks

"S. Justin Gengo" <sjgengo@aboutf ortunate[no-spam].com> wrote in message
news:10******** *****@corp.supe rnews.com...
George,

Glad you got it working. (Good eyes Karl!)

Just a note: You could also use a CompareValidato r instead of the
RegularExpressi onValidator. If you leave the CompareValidato r's
ControlToCompar e property blank and set it's Operator property to
DataTypeCheck you may then set it's Type property to check if a value
entered is a String, Integer, Double, Date, or Currency.

While I love that I can do almost anything with the regular expression
validator I find simple data type checks much easier to set up with the
CompareValidato r.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"George Durzi" <gd****@hotmail .com> wrote in message
news:uJ******** *****@TK2MSFTNG P10.phx.gbl...
> Karl,
> Thank you again, that worked perfectly.
>
> And thanks for the regex refining tip :)
>
> "Karl" <none> wrote in message
> news:OO******** ******@tk2msftn gp13.phx.gbl...
>> I think the regularexpressi onvalidator automatically puts ^ at the start > and
>> $ at the end...2d DOES match ^[+]?[0-9]\d* but it DOES NOT match
>> ^[+]?[0-9]\d*$ (note the extra $ at the end). That's the difference
>> between the two.
>>
>> Also, [0-9]\d* can be rewritten as \d+
>>
>> Karl
>>
>> "George Durzi" <gd****@hotmail .com> wrote in message
>> news:%2******** **********@tk2m sftngp13.phx.gb l...
>> > If I have a regexvalidator in a webform with a validation expression of >> > ^[+]?[0-9]\d* and I put the text 2d in a text box being validated by
> this
>> > validator, the validator fires.
>> >
>> > This regex is a simple one that only allows the user to enter
>> > integer
>> > values.
>> >
>> > However, if I do this on the server side like this
>> >
>> > Regex rx = new Regex(@"^[+]?[0-9]\d*");
>> > Match mt = rx.Match("2d");
>> >
>> > I get success!!!! why?? is there an option I should be setting?
>> >
>> >
>>
>>
>
>



Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
1771
by: Des Small | last post by:
I want to use sets and regular expressions to implement some linguistic ideas. Representing sounds by symbols, and properties (coronal or velar articulation; voicedness) by sets of symbols with those properties, it is natural to then map these sets, and intersections of them, to regular expressions to apply to strings. The question is, what regular expression should correspond to the empty set? I've provisionally gone with "(?!.*)",...
1
4167
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make regular expressions easier to create and use (and in my experience as a regular expression user, it makes them MUCH easier to create and use.) I'm still working on formal documentation, and in any case, such documentation isn't necessarily the...
4
5149
by: Buddy | last post by:
Can someone please show me how to create a regular expression to do the following My text is set to MyColumn{1, 100} Test I want a regular expression that sets the text to the following testMyColumn{1, 100}Test Basically I want the regular expression to add the word test infront of the
4
3220
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go over each document, find out if it contains a header and/or a footer and extract only the main content part. The headers and the footers have no specific format and I have to detect and remove them using a list of strings that may appear as...
11
5371
by: Dimitris Georgakopuolos | last post by:
Hello, I have a text file that I load up to a string. The text includes certain expression like {firstName} or {userName} that I want to match and then replace with a new expression. However, I want to use the text included within the brackets to do a lookup so that I can replace the expression with the new text. For example:
7
3818
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I want to avoid that. My question here is if there is a way to pass either a memory stream or array of "find", "replace" expressions or any other way to avoid multiple copies of a string. Any help will be highly appreciated
25
5147
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART (CONDUCTION DEFECT) 37.33/2 HEART (CONDUCTION DEFECT) WITH CATHETER 37.34/2 " the expression is "HEART (CONDUCTION DEFECT)". How do I gain access to the expression (not the matches) at runtime? Thanks, Mike
1
4376
by: Allan Ebdrup | last post by:
I have a dynamic list of regular expressions, the expressions don't change very often but they can change. And I have a single string that I want to match the regular expressions against and find the first regular expression that matches the string. I've gor the regular expressions ordered so that the highest priority is first (if two or more regular expressions match the string I want the first one returned) The code that does this has...
1
3388
by: NvrBst | last post by:
I want to use the .replace() method with the regular expression /^ %VAR % =,($|&)/. The following DOESN'T replace the "^default.aspx=,($|&)" regular expression with "": --------------------------------- myStringVar = myStringVar.replace("^" + iName + "=,($|&)", ""); --------------------------------- The following DOES replace it though: --------------------------------- var match = myStringVar.match("^" + iName + "=,($|&)");
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8869
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4368
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1775
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.