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.');

 }
Advertisements

Let me know what you think .. :)

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s