0
私はgoogleを清掃していて、特殊文字が前記文字列に含まれているときにユーザーがフォームを送信しようとするとエラーメッセージを表示する文字列に正規表現や何らかの属性を追加できる方法を探していますか? (必要な属性に類似)ASP.NETでは、文字列内に特殊文字を使用できない属性を追加することは可能ですか?
例:
Allowed -> Username
Not Allowed -> User'Name,&
C#クラス:
public partial class Client
{
public int CID { get; set; }
[Required(ErrorMessage ="This field is Required")]
public string Company { get; set; }
[Required(ErrorMessage = "This field is Required")]
public string Email { get; set; }
[Required(ErrorMessage = "This field is Required")]
public string Location { get; set; }
[Required(ErrorMessage = "This field is Required")]
public string Phone { get; set; }
[Required(ErrorMessage = "This field is Required")]
[DataType(DataType.Password)]
public string Password { get; set; }
[DataType(DataType.Password)]
[Required(ErrorMessage = "This field is Required")]
[DisplayName("Confirm Password")]
[Compare("Password")]
public string ConfirmPassword { get; set; }
[DefaultValue(false)]
[DisplayName("Special Client")]
public Nullable<bool> Special { get; set; }
[Range(0, int.MaxValue, ErrorMessage = "The value must be greater than 0")]
[DisplayName("Monthly Purchased Hours")]
public int HoursPayed { get; set; }
public string LoginErrorMessage { get; set; }
がこれまでに何か役に立つ見つかっていないので、試してみ何上の任意のヒントや有益なコメントは次のようになり素晴らしいです、ありがとう!
甘い、今試してみて、感謝! – Rolthar
@Roltharデフォルトでは、目立たない検証で動作します。これは、RequiredAttributeの使用法と同じくらい簡単です。楽しむ! – cloudikka
もう一度ありがとう!それは魅力のように働いています:) [正規表現(@ "[^ \' | \〜| \!| \ @ | \#| \ $ | \%| \^| \&| \ * | \ )\ "| \:| \"] "、ErrorMessage =" \\ | \\ "| \" | \\ | \ '| \ 012 |会社名の特殊文字は許可されていません! ")] – Rolthar