Regular expression matching and calculating
I have a input field in which users specify file size in Mb, so for gb they have to calculate right now.
I want to change the input fields value automatically in calculated Mbs if users type gb
after the number.
Example: 1024mb = 1gb
So if a user types 5gb in input field jquery takes the value onchange开发者_高级运维 and updates the fields value after calculating it which would be 5 * 1024 = 5120
in this case.
$('#fileSize').change(function(){
var sz = $(this).val().match(/(\d+)gb/i);
if(sz.length > 1){
$(this).val(parseInt(sz[1])*1024);
}
});
精彩评论