Doubt about RG - what is the best way to control the field?

0

I'm opening this topic to hear from you how you've been working on the issue of adding RG to forms.

I think a common concern of everyone when working with forms is that data control is in our hands - not the user's hand.

For this, the better formatted and controlled each field, the better.

One of my big problems is how to control the RG field.

That's why - and for most of the clients I work with, the RG is unnecessary - I somehow convince the client to "ignore" the field in their forms, but now I'm having to work with the RG that is required for a client.

As I do not have a lot of experience, I would like to know how you have worked with RG - whether you are leaving the field open, controlling or controlling in any way.

From what I saw, read, re-read, the best way to control the field is to lock it to only digits - and format it as XXX.XXX.XXX-X - and inform the user that if the digit is " X "(which is why I replace the 10 in the digit) replace with ZERO.

I do not know if this is the best way to do it - and if it will cover 100% of the reality of the RGs .. (the only letter we have in the RG is X in the digit?)

My need is not a VERIFIER - because this is impossible - but only a MASK control - to avoid completely random data and leave the field as standardized as possible.

The important thing is that the mask is 100% compatible with all types of RGs.

    
asked by anonymous 06.09.2016 / 18:04

2 answers

-2

have this validator I use

    function validacpf( cpf )
{
  var i;
  s = cpf;
  var c = s.substr(0,9);
  var dv = s.substr(9,2);
  var d1 = 0;
   for (i = 0; i < 9; i++)
  {
    d1 += c.charAt(i)*(10-i);
  }
  if (d1 == 0)
  {
   alert("CPF Invalido");
   return false;
  }
  d1 = 11 - (d1 % 11);
  if (d1 > 9) d1 = 0;
  if (dv.charAt(0) != d1)
  {
   alert("CPF Invalido");
   return false;
  }
  d1 *= 2;
  for (i = 0; i < 9; i++) 
  {
   d1 += c.charAt(i)*(11-i);
  }
  d1 = 11 - (d1 % 11);
  if (d1 > 9) d1 = 0;
  if (dv.charAt(1) != d1)
  {
    alert("CPF Invalido");
    return false;
   }
  return true;
 }
    
06.09.2016 / 18:16
-2

With the masked input you should use as follows

$("#RG").mask("99.999.999.9?99-*");

so the last field becomes optional and the person can put the X if it has.

It's always good that you do a validation of RG tbm look at this link below for a validator in javascript

link

It is always good to prevent the user from doing "anything", this is always the problem

    
06.09.2016 / 18:11