I have a% w / o of% that defines the points by the maximum number of digits.
Expression:
function Rg(v){
v=v.replace(/\D/g,"");
if(v.length == 9) v=v.replace(/(\d{2})(\d{3})(\d{3})(\d{1})$/,"$1.$2.$3-$4");
return v
}
expressão regular
RG :
But I would like an expression that standardizes with different digits. Example:
88.888.888-8
RG :
Without using another 8.888.888-8
as the following example:
function Rg(v){
v=v.replace(/\D/g,"");
if(v.length == 9) v=v.replace(/(\d{2})(\d{3})(\d{3})(\d{1})$/,"$1.$2.$3-$4");
if(v.length == 8) v=v.replace(/(\d{1})(\d{3})(\d{3})(\d{1})$/,"$1.$2.$3-$4");
return v
}
Is it possible?