[英]SQL Plus Dot Net - Phone formatting tag not working
到目前為止,我一直在使用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,也可能會有所幫助。
-+ Phone標記正在執行預期的操作,但是,由於必須在全局應用,因此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.")]
或者,這是我的偏愛,讓您的語義標記保持原樣,並使用twilio之類的服務發送帶有驗證碼的文本。 讓您的用戶在隨后的表單上確認該驗證碼,您就很高興。
確認電話號碼或電子郵件確實是確保的唯一方法,並且由於您似乎正在保留客戶帳單信息,因此值得進行額外的工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.