Hello @waqas7431,
Thanks for getting in touch!
If you would like to add a comma after 3 digits, you may consider using the Custom Input Masks feature. For more details on how the Custom Input Masks works, please see our guide here.
Thanks!
Hi, thanks for your reply. could you please help me to write a custom mask. I have checked the given link and there are only a few examples and I couldn’t find the one that work for me.
Thanks!
Hello @waqas7431,
I apologize for the delay in getting back.
Sure! You can consider adding 9,999,999,999
in the Input Mask to mimic the comma separator layout you’re looking for.
Thanks!
Hi thanks for your reply. This is not what I was looking for. this mask forces me to enter 10 digits with a pattern. what if the user has a random number to enter. he/she should be able to put any value for example 999 OR 74,634 OR 3,333,333
. is this something that can be done with masks?
Thanks
Hello @waqas7431,
Currently, we do not have the feature you are looking for. I do agree it would be super helpful, though. I’ve made a note of the feature request and we’ll keep it on our radar as we plan out our roadmap for the future.
I apologize that we can’t provide what you’re looking for right now, but I appreciate the suggestion! It’s always helpful to get insights from our users.
Could you please let me know if you have any other questions?
Thanks!
Never mind, I figured it out with a JQuery code:
jQuery(document).ready(function( $ ){
// Selecting field e.g "#wpforms-139-field_8"
$('input#wpforms-139-field_8').on('blur',function(){
$(this).manageCommas();
});
// replace the field id here as well
$('input#wpforms-139-field_8').on('focus',function(){
$(this).santizeCommas();
});
String.prototype.addComma = function() {
return this.replace(/(.)(?=(.{3})+$)/g,"$1,").replace(',.', '.');
}
//Jquery global extension method
$.fn.manageCommas = function () {
return this.each(function () {
$(this).val($(this).val().replace(/(,|)/g,'').addComma());
});
}
$.fn.santizeCommas = function() {
return $(this).val($(this).val().replace(/(,| )/g,''));
}
});
And thanks for adding this feature for future updates.
Hello @waqas7431,
I’m glad to hear you got that sorted, and thank you for taking the time to let us know.
Thanks!