RegularExpressionAttribute Sınıf
Tanım
ASP.NET dinamik verilerinde bir veri alanı değerinin belirtilen normal ifadeyle eşleşmesi gerektiğini belirtir.Specifies that a data field value in ASP.NET Dynamic Data must match the specified regular expression.
public ref class RegularExpressionAttribute : System::ComponentModel::DataAnnotations::ValidationAttribute
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property, AllowMultiple=false)]
public class RegularExpressionAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
public class RegularExpressionAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false)]
public class RegularExpressionAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
[<System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property, AllowMultiple=false)>]
type RegularExpressionAttribute = class
inherit ValidationAttribute
type RegularExpressionAttribute = class
inherit ValidationAttribute
[<System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false)>]
type RegularExpressionAttribute = class
inherit ValidationAttribute
Public Class RegularExpressionAttribute
Inherits ValidationAttribute
- Devralma
- Öznitelikler
Örnekler
Aşağıdaki örnek, RegularExpressionAttribute FirstName ve LastName veri alanlarını doğrulamak için özniteliğini nasıl kullanacağınızı gösterir.The following example shows how to use the RegularExpressionAttribute attribute to validate the FirstName and LastName data fields. Normal ifade en fazla 40 büyük ve küçük harf karakter sağlar.The regular expression allows up to 40 uppercase and lowercase characters. Örnek aşağıdaki görevleri gerçekleştirir:The example performs the following tasks:
Meta veri sınıfının ve ilişkili meta veri sınıfının bir kısmını uygular.Implements a metadata partial class and the associated metadata class.
İlişkili meta veri sınıfında, RegularExpressionAttribute özniteliğini ve özel hata iletilerini belirterek adı FirstName ve LastName veri alanlarına uygular.In the associated metadata class, applies the RegularExpressionAttribute attribute to the FirstName and LastName data fields, specifying the pattern and custom error messages.
using System;
using System.Web.DynamicData;
using System.ComponentModel.DataAnnotations;
[MetadataType(typeof(CustomerMetaData))]
public partial class Customer
{
}
public class CustomerMetaData
{
// Allow up to 40 uppercase and lowercase
// characters. Use custom error.
[RegularExpression(@"^[a-zA-Z''-'\s]{1,40}$",
ErrorMessage = "Characters are not allowed.")]
public object FirstName;
// Allow up to 40 uppercase and lowercase
// characters. Use standard error.
[RegularExpression(@"^[a-zA-Z''-'\s]{1,40}$")]
public object LastName;
}
Imports System.Web.DynamicData
Imports System.ComponentModel.DataAnnotations
<MetadataType(GetType(CustomerMetaData))> _
Partial Public Class Customer
End Class
Public Class CustomerMetaData
' Allow up to 40 uppercase and lowercase
' characters. Use custom error.
<RegularExpression("^[a-zA-Z''-'\s]{1,40}$", _
ErrorMessage:="Characters are not allowed.")> _
Public FirstName As Object
' Allow up to 40 uppercase and lowercase
' characters. Use standard error.
<RegularExpression("^[a-zA-Z''-'\s]{1,40}$")> _
Public LastName As Object
End Class
Açıklamalar
Özelliğin değerlerini bir normal ifadeye göre doğrulamanız gerektiğinde RegularExpressionAttribute özniteliğini bir özelliğe uygularsınız.You apply the RegularExpressionAttribute attribute to a property when you need to validate values for the property against a regular expression. Normal ifade, geçerli değerlerin biçimini tam olarak belirtmenizi sağlar.The regular expression enables you to specify very precisely the format of valid values. Model özelliği, normal ifadeyi içerir.The Pattern property contains the regular expression. Özelliğin değeri null veya boş bir dize ("") ise, değer otomatik olarak RegularExpressionAttribute özniteliği için doğrulamayı geçirir.If the value of the property is null or an empty string (""), the value automatically passes validation for the RegularExpressionAttribute attribute. Değerin null veya boş bir dizenin olduğunu doğrulamak Için RequiredAttribute özniteliğini kullanın.To validate that the value is not null or an empty string, use the RequiredAttribute attribute.
Normal ifade, bir tam eşleşme arar ^ ve $ deseninin sonundaki ve sonunda değil, onu kullanarak aynı sonuçları üretir.The regular expression searches for an exact match, not using ^ before and $ at the end of the pattern produces the same results as using it. Bir arama sonucu için kalıbı önüne ekleyin ve ekleyin .* .For a search hit, prepend and append the pattern with .*.
Oluşturucular
| RegularExpressionAttribute(String) |
RegularExpressionAttribute sınıfının yeni bir örneğini başlatır.Initializes a new instance of the RegularExpressionAttribute class. |
Özellikler
| ErrorMessage |
Doğrulama başarısız olursa doğrulama denetimiyle ilişkilendirilecek bir hata iletisi alır veya ayarlar.Gets or sets an error message to associate with a validation control if validation fails. (Devralındığı yer: ValidationAttribute) |
| ErrorMessageResourceName |
Doğrulama başarısız olursa özellik değerini aramak için kullanılacak hata iletisi kaynak adını alır veya ayarlar ErrorMessageResourceType .Gets or sets the error message resource name to use in order to look up the ErrorMessageResourceType property value if validation fails. (Devralındığı yer: ValidationAttribute) |
| ErrorMessageResourceType |
Doğrulama başarısız olursa hata iletisi arama için kullanılacak kaynak türünü alır veya ayarlar.Gets or sets the resource type to use for error-message lookup if validation fails. (Devralındığı yer: ValidationAttribute) |
| ErrorMessageString |
Yerelleştirilmiş doğrulama hata iletisini alır.Gets the localized validation error message. (Devralındığı yer: ValidationAttribute) |
| MatchTimeoutInMilliseconds |
İşlem zaman aşımına uğramadan önce tek bir eşleştirme işlemini yürütmek için milisaniye cinsinden süreyi alır veya ayarlar.Gets or sets the amount of time in milliseconds to execute a single matching operation before the operation times out. |
| Pattern |
Normal ifade modelini alır.Gets the regular expression pattern. |
| RequiresValidationContext |
Özniteliğin doğrulama bağlamı gerektirip gerektirmediğini gösteren bir değer alır.Gets a value that indicates whether the attribute requires validation context. (Devralındığı yer: ValidationAttribute) |
| TypeId |
Türetilmiş bir sınıfta uygulandığında, bunun için benzersiz bir tanımlayıcı alır Attribute .When implemented in a derived class, gets a unique identifier for this Attribute. (Devralındığı yer: Attribute) |
Yöntemler
| Equals(Object) |
Bu örneğin belirtilen bir nesneye eşit olup olmadığını gösteren bir değeri döndürür.Returns a value that indicates whether this instance is equal to a specified object. (Devralındığı yer: Attribute) |
| FormatErrorMessage(String) |
Normal ifade doğrulaması başarısız olursa görüntülenecek hata iletisini biçimlendirir.Formats the error message to display if the regular expression validation fails. |
| GetHashCode() |
Bu örneğe ilişkin karma kodu döndürür.Returns the hash code for this instance. (Devralındığı yer: Attribute) |
| GetType() |
TypeGeçerli örneği alır.Gets the Type of the current instance. (Devralındığı yer: Object) |
| GetValidationResult(Object, ValidationContext) |
Geçerli doğrulama özniteliğine göre belirtilen değerin geçerli olup olmadığını denetler.Checks whether the specified value is valid with respect to the current validation attribute. (Devralındığı yer: ValidationAttribute) |
| IsDefaultAttribute() |
Türetilmiş bir sınıfta geçersiz kılınırsa, bu örneğin değerinin türetilmiş sınıf için varsayılan değer olup olmadığını gösterir.When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Devralındığı yer: Attribute) |
| IsValid(Object) |
Kullanıcı tarafından girilen değerin normal ifade düzeniyle eşleşip eşleşmediğini denetler.Checks whether the value entered by the user matches the regular expression pattern. |
| IsValid(Object, ValidationContext) |
Geçerli doğrulama özniteliğine göre belirtilen değeri doğrular.Validates the specified value with respect to the current validation attribute. (Devralındığı yer: ValidationAttribute) |
| Match(Object) |
Türetilmiş bir sınıfta geçersiz kılınırsa, bu örneğin belirtilen bir nesneye eşit olup olmadığını gösteren bir değer döndürür.When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Devralındığı yer: Attribute) |
| MemberwiseClone() |
Geçerli bir basit kopyasını oluşturur Object .Creates a shallow copy of the current Object. (Devralındığı yer: Object) |
| ToString() |
Geçerli nesneyi temsil eden dizeyi döndürür.Returns a string that represents the current object. (Devralındığı yer: Object) |
| Validate(Object, String) |
Belirtilen nesneyi doğrular.Validates the specified object. (Devralındığı yer: ValidationAttribute) |
| Validate(Object, ValidationContext) |
Belirtilen nesneyi doğrular.Validates the specified object. (Devralındığı yer: ValidationAttribute) |
Belirtik Arabirim Kullanımları
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Bir ad kümesini karşılık gelen bir dağıtma tanımlayıcısı kümesine eşler.Maps a set of names to a corresponding set of dispatch identifiers. (Devralındığı yer: Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Bir arabirimin tür bilgilerini almak için kullanılabilen bir nesnenin tür bilgilerini alır.Retrieves the type information for an object, which can be used to get the type information for an interface. (Devralındığı yer: Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
Bir nesnenin sağladığı tür bilgisi arabirimlerinin sayısını alır (0 ya da 1).Retrieves the number of type information interfaces that an object provides (either 0 or 1). (Devralındığı yer: Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Bir nesne tarafından sunulan özelliklere ve yöntemlere erişim sağlar.Provides access to properties and methods exposed by an object. (Devralındığı yer: Attribute) |