473,624 Members | 2,232 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RegularExpressi on Validator?

Consider the following code which validates a TextBox using
RegularExpressi on:

<form id="form1" runat="server">
<asp:TextBox id="txt1" runat="server"/>
<asp:RegularExp ressionValidato r ControlToValida te="txt1"
ValidationExpre ssion="[0-9]{5}-[0-9]{4}|[0-9]{5}" ErrorMessage
="Invalid Input" Display="Dynami c" runat="server"/>
<asp:Button id="btn" Text="SUBMIT" runat="server"/>
</form>

The above RegularExpressi on Validator control doesn't display the error
message if the text entered in the TextBox is, say, 90210. Why?

Moreover, if the text entered in the TextBox is, say, 54963-87521, then
the error message gets displayed. Why?

I want the text input to have any 5 numbers between 0 & 9 which is
validated by [0-9]{5} followed by a dash which is validated by '-' &
finally followed by either any four numbers between 0 & 9 'or' any five
numbers between 0 & 9 which is validated by [0-9]{4}|[0-9]{5}. So how
is the Validator control passing 90210 but not passing 54963-87521?

Thanks,

Arpan

Jul 28 '06 #1
3 1741
Consider the following code which validates a TextBox using
RegularExpressi on:

<form id="form1" runat="server">
<asp:TextBox id="txt1" runat="server"/>
<asp:RegularExp ressionValidato r ControlToValida te="txt1"
ValidationExpre ssion="[0-9]{5}-[0-9]{4}|[0-9]{5}" ErrorMessage
="Invalid Input" Display="Dynami c" runat="server"/>
<asp:Button id="btn" Text="SUBMIT" runat="server"/>
</form>

The above RegularExpressi on Validator control doesn't display the error
message if the text entered in the TextBox is, say, 90210. Why?

Moreover, if the text entered in the TextBox is, say, 54963-87521, then
the error message gets displayed. Why?

I want the text input to have any 5 numbers between 0 & 9 which is
validated by [0-9]{5} followed by a dash which is validated by '-' &
finally followed by either any four numbers between 0 & 9 'or' any five
numbers between 0 & 9 which is validated by [0-9]{4}|[0-9]{5}. So how
is the Validator control passing 90210 but not passing 54963-87521?

Thanks,

Arpan
It's validating as "5 digits, dash, 4 digits" or "just 5 digits".
You need to use () to give the | the required scope:
[0-9]{5}-([0-9]{4}|[0-9]{5})

But even better would be:
[0-9]{5}-[0-9]{4,5}

to accept "between 4 and 5" digits for the second group.

Hans Kesting
Jul 28 '06 #2
It's validating as "5 digits, dash, 4 digits" or "just 5 digits".
You need to use () to give the | the required scope:
[0-9]{5}-([0-9]{4}|[0-9]{5})
PLEASE DO NOT MODIFY THE REGULAREXPRESSI ON I CITED IN POST #1. I am not
asking for alternatives to that RegularExpressi on. All I want to know
is HOW does the value 90210 pass the RegularExpressi on
[0-9]{5}-[0-9]{4}|[0-9]{5}?

The RegularExpressi on validates that the value in the TextBox should
have any 5 numbers between 0 & 9 followed by a dash & finally followed
by either 4 numbers between 0 & 9 or 5 numbers between 0 to 9. This
means that after the 1st 5 numbers, there MUST BE a dash. After the
dash, there MUST BE either 4 or 5 numbers; so how does 90210 pass the
test? Where is the dash in 90210? So shouldn't 90210 fail to pass the
test then & there itself?

Arpan

Hans Kesting wrote:
Consider the following code which validates a TextBox using
RegularExpressi on:

<form id="form1" runat="server">
<asp:TextBox id="txt1" runat="server"/>
<asp:RegularExp ressionValidato r ControlToValida te="txt1"
ValidationExpre ssion="[0-9]{5}-[0-9]{4}|[0-9]{5}" ErrorMessage
="Invalid Input" Display="Dynami c" runat="server"/>
<asp:Button id="btn" Text="SUBMIT" runat="server"/>
</form>

The above RegularExpressi on Validator control doesn't display the error
message if the text entered in the TextBox is, say, 90210. Why?

Moreover, if the text entered in the TextBox is, say, 54963-87521, then
the error message gets displayed. Why?

I want the text input to have any 5 numbers between 0 & 9 which is
validated by [0-9]{5} followed by a dash which is validated by '-' &
finally followed by either any four numbers between 0 & 9 'or' any five
numbers between 0 & 9 which is validated by [0-9]{4}|[0-9]{5}. So how
is the Validator control passing 90210 but not passing 54963-87521?

Thanks,

Arpan

It's validating as "5 digits, dash, 4 digits" or "just 5 digits".
You need to use () to give the | the required scope:
[0-9]{5}-([0-9]{4}|[0-9]{5})

But even better would be:
[0-9]{5}-[0-9]{4,5}

to accept "between 4 and 5" digits for the second group.

Hans Kesting
Jul 29 '06 #3
>It's validating as "5 digits, dash, 4 digits" or "just 5 digits".
>You need to use () to give the | the required scope:
[0-9]{5}-([0-9]{4}|[0-9]{5})

PLEASE DO NOT MODIFY THE REGULAREXPRESSI ON I CITED IN POST #1. I am not
asking for alternatives to that RegularExpressi on. All I want to know
is HOW does the value 90210 pass the RegularExpressi on
[0-9]{5}-[0-9]{4}|[0-9]{5}?

The RegularExpressi on validates that the value in the TextBox should
have any 5 numbers between 0 & 9 followed by a dash & finally followed
by either 4 numbers between 0 & 9 or 5 numbers between 0 to 9. This
means that after the 1st 5 numbers, there MUST BE a dash. After the
dash, there MUST BE either 4 or 5 numbers; so how does 90210 pass the
test? Where is the dash in 90210? So shouldn't 90210 fail to pass the
test then & there itself?
READ THE REST OF MY POST!

(and don't shout)

Arpan

Hans Kesting wrote:
>>Consider the following code which validates a TextBox using
RegularExpres sion:

<form id="form1" runat="server">
<asp:TextBo x id="txt1" runat="server"/>
<asp:RegularE xpressionValida tor ControlToValida te="txt1"
ValidationExp ression="[0-9]{5}-[0-9]{4}|[0-9]{5}" ErrorMessage
="Invalid Input" Display="Dynami c" runat="server"/>
<asp:Button id="btn" Text="SUBMIT" runat="server"/>
</form>

The above RegularExpressi on Validator control doesn't display the error
message if the text entered in the TextBox is, say, 90210. Why?

Moreover, if the text entered in the TextBox is, say, 54963-87521, then
the error message gets displayed. Why?

I want the text input to have any 5 numbers between 0 & 9 which is
validated by [0-9]{5} followed by a dash which is validated by '-' &
finally followed by either any four numbers between 0 & 9 'or' any five
numbers between 0 & 9 which is validated by [0-9]{4}|[0-9]{5}. So how
is the Validator control passing 90210 but not passing 54963-87521?

Thanks,

Arpan

It's validating as "5 digits, dash, 4 digits" or "just 5 digits".
You need to use () to give the | the required scope:
[0-9]{5}-([0-9]{4}|[0-9]{5})

But even better would be:
[0-9]{5}-[0-9]{4,5}

to accept "between 4 and 5" digits for the second group.

Hans Kesting

Jul 31 '06 #4

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

Similar topics

2
1840
by: Greg | last post by:
Standar 9-digit postal code expression, copied and pasted from a web form validator expression: @"\d{5}(-\d{4})? I try to use it to validate a windows textbox, but it does not like the '?'. If the first part is matched,it doesnt care what comes afterwards. Removing the ? gives proper behavior.
4
1274
by: Learning SQL Server | last post by:
The email reg exp that ships with the RegularExpressionValidator doesnt like this email address: user@blah.ru Or any other email domain that contains only 2 letters after the dot. It *looks* like it should (I notice the qualifier at the end of the statement for 2 or more letters), but the validator always fires anyway. Anyone else notice similar behavior or do I just need some sleep?
2
2731
by: John Hoge | last post by:
I have a regex "^\d{5}$" that does not allow blanks, but the RegularExpressionValidator does not fire for empty fields. Is there a way to make it do so? I would rather not include a separate RequiredValidator for reasons of brevity and neatness. Thanks, John
1
1918
by: Nicola Farina | last post by:
Hi all, i've a form with a textbox that user "must" fill with a password. I want to check if there's a password inside, and if it's between 6 an 8 chars. I've placed a regularexpression validator pointing this textbox and with the following expression: \w{6,8}
0
948
by: MA | last post by:
Hi, I'm strugling with tho following case: I use a datalist in my asp.net application to present an interface to the use where he/she can modify some database tables. In de "update mode" I also give a possibility to "cancel" and "delete". If the user has modified the data wich returns a false for the used regex validator if also fires OnDelete or OnCancel.
2
2205
by: den 2005 | last post by:
Hi everybody, How do restrict entering these characters <>\"%';()& and telling user these caharcters are not allowed to be enter in the textbox field using RegularExpression Validator? I put in the Validation Expression property . It restrict every character execpt 0 to 9. How to fixed this? I used + in validation Expression property of Regular Expression Validator Control. All are working except when entering the character \, which...
1
1525
by: Arpan | last post by:
Using RegularExpression, I want to validate a TextBox so that the TextBox accepts only 8-digit numbers. This can be done with the following RegularExpression: {8} But how do I validate the TextBox so that it accepts 8-digit number or more than 8-digit numbers using RegularExpressions? Also how do I validate the TextBox so that it accepts 8 or more than
1
2031
by: prp | last post by:
hi all, I have a problem.Suppose I use a regularexpression validator for zip code. An User fill wrong entry in the relevant textbox then regularexpression validator fires.but user did not correct the entry and press the signup button . At that time i want setfocus on that zip textbox. all such things happen in asp.net and i want javascript for the setfocus.
5
5156
by: hamsterchaos | last post by:
<asp:RegularExpressionValidator id="valRegEx" runat="server" ControlToValidate="textbox1" ValidationExpression=" " ErrorMessage="* Please only enter alphanumeric values and make sure you are not entering in any apostrophes." display="dynamic">* I need
0
8681
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
8629
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
8341
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,...
0
8488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6112
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
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2611
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
1488
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.