Right To Left Mask Input With Jquery
I have the following mask input in jQuery: $('#id_Account').mask('9999',{placeholder:'0'}) The current behaviour of this textbox is to have zeros as placeholder to type the numb
Solution 1:
Sounds like this is a feature that the plugin doesn't support. It's simple enough to implement yourself, why not create it (and send a PR to the plugin to add it)?
Here's something to start you out:
functionprependMask(input,mask) {
var m_len = mask.length, i_len = input.length; // get |mask| - |input|
if i_len <= m_len {
return Array(m_len - i_len).join(mask[0]) + input; // prepend mask of length (|m| - |input|) to input
} else {
returninput; // no need for mask
}
}
Solution 2:
I implemented myself with something like this:
<input name="myaccount1"type="text" style="text-align:right" onchange="mask_account(this)">
This is the function:
functionmask_account(field_account){
var qty_chars = field_account.value.length;
var zeros = ''for (i=0; i < 4 - qty_chars; i++ ){
zeros= zeros + '0';
}
var new_value = zeros + field_account.value;
field_account.value = new_value;
}
Post a Comment for "Right To Left Mask Input With Jquery"