using System;
using System.Text.RegularExpressions;
public static class ChassiValidator
{
// Método principal para validar o chassi (VIN)
public static bool ValidarChassi(string chassi)
{
// 1 - Verifica se o chassi começa com "0"
if (Regex.IsMatch(chassi, @"^0", RegexOptions.IgnoreCase))
{
return false;
}
// 2 - Remove espaços do chassi
chassi = chassi.Replace(" ", "");
// 3 - Verifica se há repetição consecutiva de mais de 6 vezes a partir do 4º dígito
if (Regex.IsMatch(chassi, @"^.{3,}([0-9A-Za-z])\1{5,}", RegexOptions.IgnoreCase))
{
return false;
}
// 4 - Verifica se o chassi contém os caracteres proibidos: i, I, o, O, q, Q
if (Regex.IsMatch(chassi, @"[iIoOqQ]", RegexOptions.IgnoreCase))
{
return false;
}
// 5 - Verifica se os quatro últimos caracteres são numéricos
if (!Regex.IsMatch(chassi, @"[0-9]{4}$", RegexOptions.IgnoreCase))
{
return false;
}
// 6 - Verifica se o chassi tem exatamente 17 caracteres
if (chassi.Length != 17)
{
return false;
}
// Se todas as verificações passaram, o chassi é válido
return true;
}
}
See why 4M developers consider Sentry, “not bad.”
Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)