In my jsf page, I have an inputtext with a string value. The input should be numbers only but I want it to automatically be formatted after I enter the data. For example:
I inputted 1000, after entering the data it will be formatted to 1,000
My input text looks like so:
<h:inputText value="#{Bean.myInputText}" styleClass="strFormatter">
<p:ajax event="blur" update="@this"/>
</h:inputText>
My script looks like so:
$(".strFormatter").blur (
function() {
var strToFormat = $(this).val();
return strToFormat.replace(/(\d)(?=(\d{3})+(?1\d))g, "$1,");
})
But this does not work so my question is, how can I format my string of numbers automatically to be comma-separated after input without triggering any actions?