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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best way to validate an HTML File Input control

Status
Not open for further replies.

iaresean

Programmer
Joined
Mar 24, 2003
Messages
570
Location
ZA
Hi All;

Can anyone recommend the best way at approaching the validation of the above mentioned control. The required field part is easy.

I would like to check the validity of the path by using a regular expression or such. Will the OS of client have a bearing on this though?

I would appreciate if some could describe their approach, or even provide the 'ideal' regular expression I could use for such a check.

Much appreciated!

Sean. [peace]
 
What type of validation are you wanting to do? For Example, you could have some server-side validation that makes sure the file that was upload is of a specific size e.g.
Code:
    Public Function FileFieldSelected(ByVal FileField As System.Web.UI.HtmlControls.HtmlInputFile) As Boolean
        ' Returns a True if the passed a valid filesize
            If FileField.PostedFile Is Nothing Then Return False
            If FileField.PostedFile.ContentLength = 0 Then Return False
            If FileField.PostedFile.ContentLength > 5120000 Then Return False
            Return True
    End Function


____________________________________________________________

Need help finding an answer?

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

 
Hi ca8msm,

Always to the rescue hey? :-)

Yes I do check for those things already.

I just want to check that the typed (or selected) file path and/or name is valid (i.e. contains only valid chars and is of a valid format).

I like to have such regular expression checks on all incoming data as it makes my site more idiot-proof and more secure.

Thanks again,

Sean. [peace]
 
You can probably do some JavaScript checking (via RegEx) to see if the file path is in the correct format (although you probably won't be able to check if the file exists or anything like that). Is that what you are looking to do?


____________________________________________________________

Need help finding an answer?

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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top