|
-
Mar 2nd, 2009, 01:56 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] Validate string
My app has an input tag to allow a file to be saved. I need to validate the file name. The file naming convention needed is:
12345-results.pdf
in lowercase. Any suggestions?
Last edited by EyeTalion; Mar 4th, 2009 at 08:26 AM.
Reason: RESOLVED
It's tough being an unhandled exception...
___________
VB.NET 2008
VB.NET 2010
ORACLE 11g
CRYSTAL 11
-
Mar 2nd, 2009, 02:12 PM
#2
Re: Validate string
Hey,
Why do you need to validate the file name?
Can you not just change the file name to whatever you need it to be when you save the file on the server.
Gary
-
Mar 2nd, 2009, 03:24 PM
#3
Addicted Member
Re: Validate string
You can split up the string into separate parts and validate each part. For instance, you can strip out the first five characters and then do something like:
Integer.TryParse (first5, first5final) or something along those lines.
But then, do the numbers have to be in sequential order? Can the number be 82345? If some sort of sequential order must be maintained, then it gets real tricky. I couldn't even begin to think of how to validate that the number is in order ala '12345'. I'm sure there's a way though.
Two other words come to mind, related to your problem, regular expression.
If my post helped you, please rate it!
Languages: VB/ASP.NET 2005, C# 2008,VB6
Databases: Oracle (knowledge not currently in use), DB2
FROM Customers
WHERE We_Know_What_We_Want <> DB.Null
SELECT *
0 rows returned
-
Mar 2nd, 2009, 11:06 PM
#4
Junior Member
Re: Validate string
Does the file name strictly have to be 12345-results.pdf? That makes it pretty straight forward. Suppose you have an input tag like
Code:
<input type="text" onblur="return regexmatch()" id="mytextbox" />
Your javascript function would look like
Code:
function regexmatch()
{
var reg =new RegExp('12345-results.pdf');
var val = document.getElementById('mytextbox').value;
if(reg.test(val))
return true;
else
{
document.getElementById('mytextbox').focus();
alert("File Name not in proper format !!!");
return false;
}
}
Here once the focus is on the text box the javascript function would allow the focus to move away from the text box only if 12345-results.pdf is entered into it. I am not sure I have understood you correctly . Could you explain a bit further.
Warm Regards,
sr_jay.
 Originally Posted by EyeTalion
My app has an input tag to allow a file to be saved. I need to validate the file name. The file naming convention needed is:
12345-results.pdf
in lowercase. Any suggestions?
-
Mar 3rd, 2009, 02:03 AM
#5
Re: Validate string
Hey,
The one thing about doing client-side validation of the server name is that if someone wanted to, that check can be easily circumvented. The only real test would be to validate the file name again at the server side. Client side validation is really only going to work for "honest" users.
Gary
-
Mar 3rd, 2009, 07:38 AM
#6
Addicted Member
Re: Validate string
As Gary stated, sr_jay's solution will only work for certain users. What if someone has javascript disabled in their browser not because they want to hack sites, but because they just want it disabled? The user is not purposely trying to harm the site, however they can enter bad information on accident.
All the OP needs to do is use a regular expression validator control. It will perform the same validation as the javascript code, but since the control is server-side, it's a bit harder to circumvent.
Unfortunately, that's about all I can do to help, because EyeTailon has not given enough information. He says that '12345-results.pdf' is a naming convention, which is of little use to me. I can only ASSume that it has to be 5 numbers, a dash, a string, and a .pdf, but I could be completely wrong and it has to be 12345, then a string name, then a .pdf, or I could be wrong even still and it's something else.
If my post helped you, please rate it!
Languages: VB/ASP.NET 2005, C# 2008,VB6
Databases: Oracle (knowledge not currently in use), DB2
FROM Customers
WHERE We_Know_What_We_Want <> DB.Null
SELECT *
0 rows returned
-
Mar 4th, 2009, 06:47 AM
#7
Re: Validate string
Try this, expand to fit your needs. I'm just assuming a number followed by a name followed by strictly alphabetical extension (no MP3).
[1-9]+-[a-z]+\.[a-z]+
And I'll also emphasize that it should be both client side and server side.
-
Mar 4th, 2009, 08:04 AM
#8
Thread Starter
Frenzied Member
Re: Validate string
thanks guys for all the input...I've decided to use Geps solution and name the file myself, since I have all the info at the time of the save.
It's tough being an unhandled exception...
___________
VB.NET 2008
VB.NET 2010
ORACLE 11g
CRYSTAL 11
-
Mar 4th, 2009, 08:15 AM
#9
Re: Validate string
Hey,
Glad to hear you got a solution that works for you.
Remember to mark your thread as resolved if your question has been answered.
Gary
-
Mar 4th, 2009, 08:25 AM
#10
Thread Starter
Frenzied Member
[RESOLVED] Re: Validate string
It's tough being an unhandled exception...
___________
VB.NET 2008
VB.NET 2010
ORACLE 11g
CRYSTAL 11
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
|