Tell me how you can implement input to input in this format 12 345 , 1 345 with a space?
html:
<input type="text" name="slider"> Without the mask plug-in, and using:
input.val() replace Tell me how you can implement input to input in this format 12 345 , 1 345 with a space?
html:
<input type="text" name="slider"> Without the mask plug-in, and using:
input.val() replace I can't do it better ..
const InputFormatType = { THOUSAND: 3 }; const decorator = ( value, format = InputFormatType.THOUSAND ) => value .split( '' ) .filter( char => char !== " " ) .reverse() .reduce( ( result, char, index ) => result += (( index >= format && index % format === 0 ? " " : "" ) + char), "" ) .split( '' ) .reverse() .join( '' ); const input = document.body.querySelector('input'); input.addEventListener('input', input_inputHandler); function input_inputHandler( { target } ){ target.value = decorator( target.value ); } <input type="text"> Found the solution .toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1 " :
var val = $('input').val(); $('input').val(val.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1 ") ); $('input').change(function(){ var $this = $(this), valIn = $this.val(), valInNew = valIn.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1 "); $this.val(valInNew); }); <script src="https://code.jquery.com/jquery-2.0.3.js"></script> <input type="text" value="12345"> keyup instead of change - Alex123 456 789 123 45 6 661 and even 3 45 6 661 5 559 . - user220409http://igorescobar.imtqy.com/jQuery-Mask-Plugin/
$('input[name=slider]').mask('000 000 000', {reverse: true}); Source: https://ru.stackoverflow.com/questions/598851/
All Articles