在我看来,正则表达式可以快速完成(再次,我希望我知道正则表达式).
所以,这里是一个例子:
public bool VerifyBoxNumber (string BoxNumber) { // psudo code if (BoxNumber.FormatMatch("#-#####") return true; return false; }
如果你知道真正的代码,将使上述比较工作,请添加一个答案.
private static readonly Regex BoxNumberRegex = new Regex(@"^\d-\d{5}$"); public static bool VerifyBoxNumber (string BoxNumber) { return BoxNumberRegex.IsMatch(BoxNumber); }