Microsoft の Validation Application Block を使用しています。電話番号を保持する文字列プロパティがあります。私は RegexValidator を持っていますが、これは電話番号タイプの文字列のみがプロパティに含まれていることを確認するのに非常にうまく機能しますが、プロパティは null または空の文字列の値も許可する必要があります。
現在、値が null または空の場合、このバリデーターは失敗します。
どうすればこれを回避できますか?
(この正規表現はこの形式では少し読みにくいので、テストするためのリンクを提供しました。)
// the regex below can be found and tested at: http://regexlib.com/RETester.aspx?regexp_id=536
[RegexValidator(@"^(?:(?<1>[(])?(?<AreaCode>[2-9]\d{2})(?(1)[)])(?(1)(?<2>[ ])|(?:(?<3>[-])|(?<4>[ ])))?)?(?<Prefix>[1-9]\d{2})(?(AreaCode)(?:(?(1)(?(2)[- ]|[-]?))|(?(3)[-])|(?(4)[- ]))|[- ]?)(?<Suffix>\d{4})$", MessageTemplateResourceName = "InvalidPhoneNumberMessage", MessageTemplateResourceType = typeof(Xltech.Common.Resources.XLStrings))]
public string NotificationCellNumber {get; set;}