Adding a pound sign to an input – jquery

Trying to format this input to display as monies, with a pound sign, I have the decimal place and 2 zeroes formatted – with the following:

function isPrice(el){
    val = parseFloat(el.value);
    if (!isNaN(val)){
        el.value = parseFloat(el.value).toFixed(2);
    }
}

Been quite stuck on this..Thank you !

Answer

You can either create your own/ use the below regex to include the pound sign:

return "£" + value.toFixed(2).replace(/d(?=(d{3})+.)/g, "$&,");

Or

get the jquery plugin for currency formatting described here.

PS: If you just want the Pound sign in input fields, you have to use the character code. For Pound, it is u00A3. So:

  $('id').val('u00A3100'); 

Leave a Reply

Your email address will not be published. Required fields are marked *