i am going to upload file using file upload control in asp.net . now i want to get file name without extension using java script . i want to validate file name should be only integer format
$(function () {
$('#<%=File1.ClientID %>').change(function () {
var uploadcontrol = document.getElementById('<%=File1.ClientID%>').value;
})
})
Try this:
$('#test').change(function() {
//something like C:\fakepath\1.html
var fpath = this.value;
fpath = fpath.replace(/\\/g, '/');
var fname = fpath.substring(fpath.lastIndexOf('/')+1, fpath.lastIndexOf('.'));
console.log(fname);
});
http://jsfiddle.net/rooseve/Sdq24/
You can split it with respect to last instance of dot('.')
var uploadcontrol = document.getElementById('<%=File1.ClientID%>').value;
uploadcontrol = uploadcontrol.split('.')[uploadcontrol.split('.').length - 2];
But,
this is valid for simple case only... a much better generic answer is given at How to get the file name from a full path using JavaScript?
Take care of these things in a generic solution
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With