开发者

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);
}
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜