Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
|
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 12th, 2009, 07:15 PM
Friend of Wrox
 
Join Date: Dec 2008
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default limitation of RegularExpressionValidator?

As we all know that FileUpload control does not support file type restriction out of the box, and you have to do it on your own, for example through RegularExpressionValidator.

That's fine, so I used a validator with this expression
Code:
^.+?\.(doc|xls|jpg|ppt|pdf)$
, and it worked like charm. However if I change the regexp to
Code:
\.(doc|xls|jpg|ppt|pdf)$
, it became broken. That's strange though, as logically speaking, anything matches the first regexp also satisfies the second one...

Is there some sort of wierd restriction came with RegularExpressionValidator?
 
Old January 16th, 2009, 05:41 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Can you define "it is broken"?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old January 16th, 2009, 07:05 PM
Friend of Wrox
 
Join Date: Dec 2008
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

Quote:
Originally Posted by Imar View Post
Can you define "it is broken"?
I use one example to explain this:
  1. With the first regexp, if you select a .pdf file, it passes the validation;
  2. With thw second regexp, if you select a .pdf file, the error message shows up.
 
Old January 17th, 2009, 12:39 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Well, it works fine in JavaScript. Are you asking for only server-side validation??? I'd think that a client-side validator would work.

Here it is in pure HTML/JS:
Code:
<script>
var r1 = /^.+?\.(doc|xls|jpg|ppt|pdf)$/i
var r2 = /\.(doc|xls|jpg|ppt|pdf)$/i

function Check(fld)
{
    alert( "Test 1: " + r1.test(fld.value) + "\nTest 2: " + r2.test(fld.value) );
}
</script>
<form>
<input onchange="Check(this);">
<p>
<input onchange="Check(this);">
</form>
Did you possibly forget the "i" (or equivalent...for ignore case) in the second instance???
 
Old January 17th, 2009, 05:26 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I agree it's weird. Don't know why that doesn't work with a RegularExpressionValidator....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old January 20th, 2009, 02:07 PM
Friend of Wrox
 
Join Date: Dec 2008
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

run into another one of those situation earlier today. I have a textbox and it only accepts allnumeric string less than 14 characters long, and cannot be empty. So I used a RegularExpressionValidator, and the regexp is
Code:
^(\d{1,14})$
, but that didn't work.

I ended up use regexp
Code:
^(\d+)$
, and set MaxLength of the textbox to 14.
 
Old January 20th, 2009, 04:36 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Not clear to me why you think you need parentheses in either of those.

You should be able to just do
Code:
^\d{1,14}$
On the other hand, I don't see how the parentheses hurt.
 
Old February 13th, 2009, 12:44 AM
Friend of Wrox
 
Join Date: Dec 2008
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

Thanks Old Pedant. I end up went with java script, it is easier. RegularExpressionValidator + FileUploader seemed to be a bad combination. In many ways, that combination is not a decent solution.





Similar Threads
Thread Thread Starter Forum Replies Last Post
RegularExpressionvalidator belete ASP.NET 1.0 and 1.1 Professional 2 October 20th, 2007 01:44 PM
RegularExpressionValidator collie Visual Studio 2005 0 October 11th, 2007 07:59 AM
RegularExpressionValidator somnath.kartic ASP.NET 1.0 and 1.1 Basics 4 April 3rd, 2006 09:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.