Regular Expression....?

R

Rajeev Soni

Hi

I am looking for the regular expression for validating the allowed file types to upload like files like "zip,pdf,doc,rtf,gif,jpg,png,txt"; and the expression should not be case sensitive like it must match ZIP | zip | zIp.....

regards
rajeev
 
H

Herve MAILLARD

Hi,

Have a look at this adress : http://www.regexlib.com/Default.aspx

Regards,

H. MAILLARD

"Rajeev Soni" <[email protected]> a écrit dans le message de (e-mail address removed)...
Hi

I am looking for the regular expression for validating the allowed file
types to upload like files like "zip,pdf,doc,rtf,gif,jpg,png,txt"; and the
expression should not be case sensitive like it must match ZIP | zip |
zIp.....

regards
rajeev
 
R

Rajeev Soni

Hi,
i have this validationexpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT|doc|DOC)$"
but in the above case i need to repilcate each extension twice once in lower case and once in upper case and this expression will not accept file extension as ".TxT".

Is there any option in regular expression where we can specifiy to perform matching without considering the case of letter.

thanks
rajeev
Hi
I have already been to that, i have regular expression which validates given file type... but it is case sensitive and i need to create validation expression by getting the allowed file types from DB. So the there may be any number of extensions.

Thanks
Rajeev
 
E

Elliot M. Rodriguez

Yes: use the i modifier:
/^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT|doc|DOC)$/i



--
Elliot M. Rodriguez, MCSD
*** It would take 227 cans of Mountain Dew to kill me***



Hi,
i have this validationexpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT|doc|DOC)$"
but in the above case i need to repilcate each extension twice once in lower case and once in upper case and this expression will not accept file extension as ".TxT".

Is there any option in regular expression where we can specifiy to perform matching without considering the case of letter.

thanks
rajeev
Hi
I have already been to that, i have regular expression which validates given file type... but it is case sensitive and i need to create validation expression by getting the allowed file types from DB. So the there may be any number of extensions.

Thanks
Rajeev
 
R

Rajeev Soni

Hi

Thanks for the response... but placing "/" at start and end with "i" doesnot work..... it is also not accepting txt/TXT/doc/DOC extensions.
I am using VS.NET 2003 with IE 6 sp1.

regards
rajeev
Yes: use the i modifier:
/^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT|doc|DOC)$/i



--
Elliot M. Rodriguez, MCSD
*** It would take 227 cans of Mountain Dew to kill me***



Hi,
i have this validationexpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT|doc|DOC)$"
but in the above case i need to repilcate each extension twice once in lower case and once in upper case and this expression will not accept file extension as ".TxT".

Is there any option in regular expression where we can specifiy to perform matching without considering the case of letter.

thanks
rajeev
Hi
I have already been to that, i have regular expression which validates given file type... but it is case sensitive and i need to create validation expression by getting the allowed file types from DB. So the there may be any number of extensions.

Thanks
Rajeev
 
C

Chris R. Timmons

Hi

Thanks for the response... but placing "/" at start and end with
"i" doesnot work..... it is also not accepting txt/TXT/doc/DOC
extensions. I am using VS.NET 2003 with IE 6 sp1.

Rajeev,

The /i modifier works in Perl, but not in .Net. To make a regex
case-insensitive in .Net, use the case-insensitive (?i) mode
modifier. It should be the first thing in the regex. For example:

(?i)^.*?\.(txt|zip|doc|exe)$

will match a string ending in .txt, .zip, .doc or .exe, regardless of
the string's case.


Hope this helps.

Chris.
 
R

Rajeev Soni

Hi Chris,
placing "(?i)" at the start of expression also doesnot work, it gives me JavaScript Error "Syntax Error in regular expression".
i tried with both ways
ValidationExpression = "(?i)^.*?\.(txt|zip|doc|exe)$"
ValidationExpression = "(?i)^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+(?i)\.(txt|TXT|doc|DOC)$".

I am using
- WinXP Professional
- VS.NET 2003
- Framework 1.1
- IE6 with SP1

Thanks
Rajeev
 
C

Chris R. Timmons

Hi Chris,
placing "(?i)" at the start of expression also doesnot work, it
gives me JavaScript Error "Syntax Error in regular expression".
i tried with both ways
ValidationExpression = "(?i)^.*?\.(txt|zip|doc|exe)$"
ValidationExpression =
"(?i)^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w
]*))+(?i)\.(txt|TXT|doc|DOC)$".

I am using
- WinXP Professional
- VS.NET 2003
- Framework 1.1
- IE6 with SP1

Rajeev,

OK. I didn't know you were using JavaScript.

For client-side JavaScript in IE6, there are two different syntaxes
for regular expressions. They both work the same:

http://msdn.microsoft.com/library/en-
us/script56/html/js56jsobjregexpression.asp

Here's an example:


<HTML>
<HEAD>
<TITLE>Case-Insensitive JavaScript Regular Expression</TITLE>
</HEAD>
<BODY>
<SCRIPT language="JavaScript">
<!--
function IsFilenameValid_Version1(filename)
{
// Regex syntax using a RegExp object.
var re = new RegExp("^.*?\\.(txt|zip|doc|exe)$", "i");
return filename.match(re);
}

function IsFilenameValid_Version2(filename)
{
// Regex syntax using the native regex type.
var re = /^.*?\\.(txt|zip|doc|exe)$/i;
return filename.match(re);
}

var filename1 = "c:\\folder\\filename.TXT";
var filename2 = "c:\\folder\\filename.ppt";

if (IsFilenameValid_Version1(filename1))
document.write(filename1 + " is valid.<BR>");
else
document.write(filename1 + " is not valid.<BR>");

if (IsFilenameValid_Version2(filename2))
document.write(filename2 + " is valid.<BR>");
else
document.write(filename2 + " is not valid.<BR>");

//-->
</SCRIPT>

</BODY>
</HTML>


Hope this helps.

Chris.
 
R

Rajeev Soni

Thanks Chris,
i wrote Custom validator javascript function on to the client side using
function IsFilenameValid_Version1(filename) but
function IsFilenameValid_Version2(filename) doesnot seem to work try and give it a valid file... it returns false.

thanks
rajeev

Chris R. Timmons said:
Hi Chris,
placing "(?i)" at the start of expression also doesnot work, it
gives me JavaScript Error "Syntax Error in regular expression".
i tried with both ways
ValidationExpression = "(?i)^.*?\.(txt|zip|doc|exe)$"
ValidationExpression =
"(?i)^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w
]*))+(?i)\.(txt|TXT|doc|DOC)$".

I am using
- WinXP Professional
- VS.NET 2003
- Framework 1.1
- IE6 with SP1

Rajeev,

OK. I didn't know you were using JavaScript.

For client-side JavaScript in IE6, there are two different syntaxes
for regular expressions. They both work the same:

http://msdn.microsoft.com/library/en-
us/script56/html/js56jsobjregexpression.asp

Here's an example:


<HTML>
<HEAD>
<TITLE>Case-Insensitive JavaScript Regular Expression</TITLE>
</HEAD>
<BODY>
<SCRIPT language="JavaScript">
<!--
function IsFilenameValid_Version1(filename)
{
// Regex syntax using a RegExp object.
var re = new RegExp("^.*?\\.(txt|zip|doc|exe)$", "i");
return filename.match(re);
}

function IsFilenameValid_Version2(filename)
{
// Regex syntax using the native regex type.
var re = /^.*?\\.(txt|zip|doc|exe)$/i;
return filename.match(re);
}

var filename1 = "c:\\folder\\filename.TXT";
var filename2 = "c:\\folder\\filename.ppt";

if (IsFilenameValid_Version1(filename1))
document.write(filename1 + " is valid.<BR>");
else
document.write(filename1 + " is not valid.<BR>");

if (IsFilenameValid_Version2(filename2))
document.write(filename2 + " is valid.<BR>");
else
document.write(filename2 + " is not valid.<BR>");

//-->
</SCRIPT>

</BODY>
</HTML>


Hope this helps.

Chris.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top