Notifications
Clear all

[Closed] illegal character filter

What’s the easiest way to ensure a user doesn’t place any illegal characters in a filename?
Thnx

2 Replies
 lo1

there are many ways to go about this. Here is one:

fn validateFilename f =
(
	for c in ((dotnetclass "System.IO.Path").GetInvalidFileNameChars()) do f = substituteString f c "_"
	f
)

if i need just to check that user doesn’t type illegal characters i would do it with regex:
http://stackoverflow.com/questions/62771/how-check-if-given-string-is-legal-allowed-file-name-under-windows