Regular Expression....?

  • Thread starter Thread starter Rajeev Soni
  • Start date Start date
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
 
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
 
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
 
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
 
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
 
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.
 
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
 
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.
 
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.
 
Back
Top