|
-
Jan 24th, 2003, 06:43 AM
#1
regular expressions in javascript
Hi,
I have a simple doubt in client side javascript.
I have a string "ASHDHSJDHASLJDMICROADHHASJD.TIF"
I wish to find out if the last four characters in this string
are ".TIF" This could be in any case (upper case, lower case, mixed case)
If the letters are present, I want to alert("TRUE) else alert("FALSE");
How do I use a regular expression for this particular case?
Cheers!
Abhijit
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
Jan 24th, 2003, 08:42 AM
#2
This doesn't use a RegExp but is will do the job
Code:
function GetExt(val){
var str = new String(val);
str = str.substring(str.length -4,str.length);
return (str.toUpperCase() == '.TIF')?true:false;
}
-
Jan 24th, 2003, 03:18 PM
#3
Black Cat
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
-
Jan 25th, 2003, 01:34 AM
#4
Thanks a lot folks.
That getExt helps me a lot. I had written something like this.
PHP Code:
function matchDemo(str)
{
var st = new String(str);
var re = new RegExp("(\.)(tif)","i","$");
re.exec(st);
if (RegExp.$1 != '')
{
alert(RegExp.$1);
return true;
}
else
{
//alert('No Match Found');
return false;
}
}
But its not working correctly. Wondering if anyone could resolve it.
Cheers!
Abhijit
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
Jan 25th, 2003, 09:20 AM
#5
Member
foo.tif -- Matches. The alert displays a period
foo.tif.wav -- Matches, but shouldn't
footif -- Matches, but shouldn't
Try this instead:
return /\.tif$/i.test(str)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|