private bool CheckRFC(string RFCString) { try { if ((string.IsNullOrEmpty(RFCString)) || (string.IsNullOrWhiteSpace(RFCString))) //Verifica que no venga nulo o en blanco el RFC { throw new ArgumentNullException ("RFCString","RFC esta vacío"); } else { RFCString = String.Concat(RFCString.Where(c => !Char.IsWhiteSpace(c))); // Quita cualquier espacio en blanco de la cadena RFCString = RFCString.ToUpper(); // Pasa a mayusculas el RFC if (RFCString.Length == 13) { // try { string rfcName = (RFCString.Substring(0,4)); string rfcDate = (RFCString.Substring(4,6)); string rfcHomoClave = (RFCString.Substring(10,3)); bool isDigitPresent = rfcName.Any(c=> char.IsDigit(c)); if (isDigitPresent) { throw new Exception("Existe un digito en los primeros 4 caracteres del RFC"); return false; } else // Es correcto el nombre en el RFC { if (rfcDate.All(char.IsDigit)) // Es correcta la fecha de nacimiento { return true; } else // Es incorrecta la fecha de nacimiento { throw new Exception("Existen caracteres en la fecha de nacimiento del RFC"); return false; } } } catch (Exception) { throw; } } else { throw new ArgumentException("RFCString","Error en la longitud del RFC, deben ser 12 caracteres"); return false; } } } catch (Exception ex) { throw; } (责任编辑:) |