Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expression Validator 1

Status
Not open for further replies.

peebman2000

Programmer
Nov 28, 2006
30
US
Hello everyone, I have using the regular expression validator for an app to only upload .txt files only. When I run the app and I choose file other than .txt file it shows my validation error, but when I choose a .txt file also it still shows my validation error. It basically shows the validation error no matter what file I choose, i want it to only show the validation error when choosing non .txt files. Here is my code below, does anyone know why the valdation error continues to show up, no matter what file I select?

<asp:RegularExpressionValidator ID="FileUploadValidator" runat="server" ControlToValidate="FileUpload1"
ErrorMessage="Upload .Txt files only." Style="z-index: 104; left: 551px; position: absolute;
top: 125px" ValidationExpression='"^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.txt|.TXT)$"'></asp:RegularExpressionValidator>
 
Are you saying the regular expression is incorrect or that it isn't being applied correctly? If it's the former, try using the Regulator from:



____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.
 
I think it would just be easier to get the last 3 characters of the postedfile name and see it = "txt
 
yeah, i agree with jbenson's way.

i think this will do the trick:

<asp:RegularExpressionValidator ID="FileUploadValidator" runat="server" ControlToValidate="FileUpload1"
ErrorMessage="Upload .Txt files only." Style="z-index: 104; left: 551px; position: absolute;
top: 125px" ValidationExpression='.+(\.txt|\.TXT)$'></asp:RegularExpressionValidator>

Known is handfull, Unknown is worldfull
 
The only guaranteed method would be to check server-side though (but this won't stop the content being posted to the server, nor will it stop someone renaming a file before uploading it).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
yeah, that too you should always check the content type so that invalid content does not get into the system (some DLL renamed as .txt)...

Known is handfull, Unknown is worldfull
 
Hey guys thanks for all of your replys, I tried VBKris method and it worked and I found the Regular expression libray at and that worked too. Thanks for all your replys. Keep an ey out for me, I'll be post some more questions. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top