Comments (8)
I think that is what you want:
http://jsfiddle.net/5zc45/
Hope it helps.
from jquery-mask-plugin.
o sinal negativo é opcional e, neste caso, a sua solução não resolve
apenas troquei o S
por Z
e funcionou... não entendi o porquê...
mas aproveitei sua solução para definir que o primeiro número após o sinal deve ser obrigatório, para não validar apenas o sinal
.mask("Z0999999999", { translation: { 'Z': { pattern: /\-/, optional: true } } });
from jquery-mask-plugin.
Provavelmente não funcionou por isso:
Default Mask Legend
0: Only Numbers
9: Only Numbers but optional
A: Numbers and Letters
S: Only A-Z and a-z characters
http://igorescobar.github.io/jQuery-Mask-Plugin/
from jquery-mask-plugin.
Neste link, eu fiz u exemplo do que você precisa:
http://jsfiddle.net/5zc45/
Funcionou usando o S mesmo.
from jquery-mask-plugin.
sei que já fechei a solicitação, já que o problema inicial foi resolvido, mas tem como não definir a quantidade de caracteres da máscara? por exemplo, quero apenas números, com sinal negativo opcional?
(se preferir abro outra solicitação)
from jquery-mask-plugin.
No momento nao tem como. Você precisa definir o tamanho da mascara.
On Aug 26, 2013 11:11 AM, "Tetri Mesquita" [email protected] wrote:
sei que já fechei a solicitação, já que o problema inicial foi resolvido,
mas tem como não definir a quantidade de caracteres da máscara? por
exemplo, quero apenas números, com sinal negativo opcional?(se preferir abro outra solicitação)
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/51#issuecomment-23264855
.
from jquery-mask-plugin.
tetri, talvez você possa usar as opções do plugin para alterar o tamanho dinamicamente e ir testando o que precisa, eu por exemplo pra fazer mascara para Notas escolares, tinha problemas para definir a mascara quando a nota 10,0 mas o restante era de 0,0 à 9,9. Usei então a função onKeyPress do plugin para conseguir, e uma mascara dinâmica em forma de função:
var opt = {
translation: { 0: '0' },
onKeyPress: function(a, b, c, d) {
if(!a)
return;
var reg = /^(1|10|1,|10,\d*)$/g,
m = '';
m = (a.match(reg)) ? '99,0' : '9,9';
c.mask(m, d);
}
};
var maskNota = function(a,b){
var reg = /^(1|10|1,|10,\d*)$/g,
m = '';
m = (a.match(reg)) ? '99,0' : '9,9';
return m;
};
$(el).mask(maskNota, opt);
Talvez você consiga o mesmo redefinindo a mascara após o onComplete, exemplo:
$(document).ready(function(){
var options = {
translation: { 'S': { pattern: /\-/, optional: true } },
onComplete: function(a, b, c, d) {
console.log('completado');
if(a.length>=14) return; // Limitar Tamanho máximo
if(a.length>=10) {
mask += "9";
c.mask(mask, d);
}
}
};
var mask = "S9999999999"; // Defini tamanho mínimo
$('.field').mask(mask, options);
});
from jquery-mask-plugin.
Isso aqui resolve notas escolares:
var maskNota = function(val){
return ( val.replace(/\D/g, '') == '100' ) ? '10,0' : '0,09';
},
optionsZ = {onKeyPress: function(val, e, field, options){
field.mask(maskNota.apply({}, arguments), options);
}
};
$('.mask-nota').mask(maskNota, optionsZ);
from jquery-mask-plugin.
Related Issues (20)
- Cant get the money mask to work HOT 2
- Multiple mask in data-mask using array
- .mask() method doesn't work on inputs with type "number" HOT 2
- jQuery 'input' event receiving unexpected value
- Replace lowercase with Uppercase HOT 1
- Mask allowing partially filled input to be submitted
- Special Characters in the pattern? HOT 1
- jQuery Mask Input
- Masking hour and prevent incorrect hours HOT 4
- 'Uncaught TypeError: $(...).mask is not a function' error on .NET Core MVC app. HOT 4
- Donations dont work on your page
- Ns
- mask('0.0.0') transform to 0.00??
- How to remove Masking on Form Submit HOT 1
- Additional server-side (PHP) checking libraries HOT 1
- Data mask reverse on Phone with DDD
- Can i do this kind of mask ?
- AVAST is understanding that it is a virus! HOT 7
- How to apply mask to string value not element
- Automatically enter the required numbers/letters?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jquery-mask-plugin.