mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 22:23:12 +00:00
37 lines
1,010 B
C#
37 lines
1,010 B
C#
using System.Text.RegularExpressions;
|
|
|
|
namespace SeaHaven.Services.Helpers
|
|
{
|
|
public static class WorkOrderNumberNormalizer
|
|
{
|
|
private const int RequiredLength = 11;
|
|
|
|
public static bool TryNormalize(string? input, out string normalized, out string? error)
|
|
{
|
|
normalized = "";
|
|
error = null;
|
|
|
|
if (string.IsNullOrWhiteSpace(input))
|
|
{
|
|
error = "WO number is required.";
|
|
return false;
|
|
}
|
|
|
|
var digits = Regex.Replace(input.Trim(), @"\D", "");
|
|
if (digits.Length == 0)
|
|
{
|
|
error = "WO number must contain digits.";
|
|
return false;
|
|
}
|
|
|
|
if (digits.Length > RequiredLength)
|
|
{
|
|
error = $"WO number cannot exceed {RequiredLength} digits.";
|
|
return false;
|
|
}
|
|
|
|
normalized = digits.PadLeft(RequiredLength, '0');
|
|
return true;
|
|
}
|
|
}
|
|
}
|