简体   繁体   English

SQL Plus点网-电话格式标记不起作用

[英]SQL Plus Dot Net - Phone formatting tag not working

I'm using SQL+ dot net and really liking it so far, but I'm having trouble with the formatting for phone number. 到目前为止,我一直在使用SQL + dot net并真的很喜欢它,但是我在电话号码格式设置方面遇到了麻烦。 With the following code: 使用以下代码:

--+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

The email and credit card tags work as expected, but the phone number seems to only prevent letters, and allows numbers like 1234 etc. What am I doing wrong? 电子邮件和信用卡标签可以按预期工作,但是电话号码似乎只能阻止字母,并允许使用1234等数字。我在做什么错了?

The generated code is as follows: 生成的代码如下:

    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; }
        }
}
}

So I received a response from sqlplus.net feedback and the answer they gave me was as follows, might help someone even if you're not using sql+ dot net. 因此,我收到了来自sqlplus.net反馈的响应,他们给我的答案如下,即使您不使用sql + dot net,也可能会有所帮助。

The --+Phone tag is doing what is expected, however, the logic for that annotation in c# is quite liberal since it has to apply globally. -+ Phone标记正在执行预期的操作,但是,由于必须在全局应用,因此c#中该注释的逻辑非常宽松。 For your case you can do one of the following: Use the --+RexExPattern tag along with an appropriate supplemental tag for the error message like so. 对于您的情况,您可以执行以下操作之一:对错误消息使用-+ RexExPattern标记以及适当的补充标记,如下所示。

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

That would translate to the following data annotation. 这将转换为以下数据注释。

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

Or, and this would be my preference, leave your semantic tags the way they are, and use a service like twilio to send a text with a verification code. 或者,这是我的偏爱,让您的语义标记保持原样,并使用twilio之类的服务发送带有验证码的文本。 Have your user confirm that verification code on a subsequent form post, and you are golden. 让您的用户在随后的表单上确认该验证码,您就很高兴。

Confirming the phone number, or email for that matter, is really the only way to be sure, and since it looks like you are persisting customer billing information, it would be worth the extra work. 确认电话号码或电子邮件确实是确保的唯一方法,并且由于您似乎正在保留客户帐单信息,因此值得进行额外的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM