SQL加点网 - 电话格式标签不起作用



我正在使用sql dot net,并且真的很喜欢它,但是我在电话号码的格式上遇到了麻烦。使用以下代码:

--+SqlPlusRoutine
    --&Author=Vincent Grazapoli
    --&Comment=Inserts a new Customer Billing Record and returns the new CustomerBillingId
    --&SelectType=NonQuery
--+SqlPlusRoutine
CREATE PROCEDURE [dbo].[CustomerBillingInsert]
(
    @CustomerBillingId int output,
--+Required
    @CustomerId int,
--+Required
--+StringLength=8,64
--+Email
    @Email varchar(64),
--+Required
--+StringLength=16,20
--+CreditCard
    @CreditCard varchar(20),
--+Required
--+StringLength=10,16
--+Phone
    @Phone varchar(16),
--...
-- other parameters

电子邮件和信用卡标签按预期工作,但电话号码似乎只能阻止字母,并允许诸如1234等的数字等。我在做什么错?

生成的代码如下:

    public class CustomerBillingInsertInput
        {
            [Required(AllowEmptyStrings = false)]
            public int? CustomerId { set; get; }
            [EmailAddress]
            [DataType(DataType.EmailAddress)]
            [Required(AllowEmptyStrings = false)]
            [StringLength(64, MinimumLength = 8)]
            public string Email { set; get; }
            [CreditCard]
            [DataType(DataType.CreditCard)]
            [Required(AllowEmptyStrings = false)]
            [StringLength(20, MinimumLength = 16)]
            public string CreditCard { set; get; }
            [Phone]
            [DataType(DataType.PhoneNumber)]
            [Required(AllowEmptyStrings = false)]
            [StringLength(16, MinimumLength = 10)]
            public string Phone { set; get; }
//Other properties
            /// <summary>
            /// Use this method to validate the instance.
            /// If the method returns false, the ValidationResults list will be populated.
            /// </summary>
            public bool IsValid()
            {
                ValidationResults = new List<ValidationResult>();
                return Validator.TryValidateObject(this, new ValidationContext(this), ValidationResults, true);
            }
            /// <summary>
            /// ValidationResults populated from the IsValid() call.
            /// </summary>
            public List<ValidationResult> ValidationResults{ set; get; }
        }
}
}

,所以我收到了sqlplus.net反馈的回复,他们给我的答案如下,即使您不使用SQL DOT NET,也可能会对某人有所帮助。

- 电话标签正在执行预期的事情,但是,C#注释的逻辑非常自由,因为它必须在全球范围内应用。对于您的情况,您可以执行以下操作之一:使用 - rexexpattern标签以及适当的补充标签,用于此类错误消息。

--+Required
--+StringLength=10,16
--+Phone
--+RegExPattern=^[0-9]{10,12}$
    --&ErrorMessage=Phone is not a vaid format.
    @Phone varchar(16),

将转化为以下数据注释。

[RegularExpression(@"^[0-9]{10,12}$",ErrorMessage = "Phone is not a vaid format.")]

or,这是我的偏爱,请按照自己的方式离开您的语义标签,并使用Twilio之类的服务发送带有验证代码的文本。让您的用户在后续表单上确认验证代码,并且您是黄金。

确认电话号码或电子邮件的电子邮件确实是确定的唯一方法,并且由于您似乎正在坚持客户收费信息,因此值得额外的工作。

最新更新