8
I have a expressão regular
which defines the points according to 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
}
RG :
88.888.888-8
But I would like an expression that Padrones with different digits. Example:
RG :
8.888.888-8
Without the use of another if
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
}
It is possible?
this rule does not apply to all states. In Minas Gerais have Rgs with the format
MG-14.808.688
– Erick M. Sprengel