Monthly Archives: January 2014

Regular Expression – Javascript- To check filename to see if alpha numeric characters

Ok here is a quick regular expression to check if a file name only contains alpha numeric characters  also we need to allow the period sign.

/^[0-9a-zA-Z\.]*$/

This allows numbers, letters and the period symbol.

The full code,

var filename = fullfilepath.replace(/^.*[\\\/]/, ''); // this is to get only the file name, file upload field gives the full path

 if (!filename.match(/^[0-9a-zA-Z\.]*$/)) {
 alert('File name should only containg letters and numbers, please rename image file and upload.');

 }