Alex
Alex

Reputation: 40395

Regex to check file name

I am looking for a regex query to verify a name of file and make sure that it contains only English characters, numbers or these characters [,],-, _

However it should not allow characters like these: ÿ¿ÿ¿ÿ¿ÿ¿ÿ¿ÿ¿ÿ¿ÿ³J

Thanks

Upvotes: 0

Views: 387

Answers (2)

Franz
Franz

Reputation: 11553

The regex looks like this:

/^[A-Za-z0-9\[\]\-_]+$/

Note that this does not allow empty strings ;)

Upvotes: 1

Tomalak
Tomalak

Reputation: 338208

^[a-zA-Z0-9.\[\]_-]+$

I've added the dot as a possibility, other than that the above requires at least one ASCII letter, digit, square bracket, underscore or dash (minus sign).

Upvotes: 1

Related Questions