Skip to content

Instantly share code, notes, and snippets.

@alanef
Last active December 15, 2019 18:07
Show Gist options
  • Select an option

  • Save alanef/4dcee5c05c1619cb3db6a5d19be6a041 to your computer and use it in GitHub Desktop.

Select an option

Save alanef/4dcee5c05c1619cb3db6a5d19be6a041 to your computer and use it in GitHub Desktop.

This script changes a text input field into one witha £ prefix and number only

Change the id or selector - the example shows #input_1_7 which is Gravity forms notation ( Form 1 field 7 )

Easiest way it to add an html block on the form page - although of course you can enqueue scripts etc

other ways

I'd love for someone to show me how to do this in pure JS without jQuery or ES6

<script>
(function ($) {
'use strict';
$(document).ready(function ($) {
$("#input_1_7").blur(function () {
$(this).val('£' + $(this).val().replace(/[^0-9]+/g, ''));
});
});
})(jQuery);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment