ValidationExpression Property

Sets or returns the regular expression assigned to be the validation criteria. The default value is an empty string ("").

public string ValidationExpression {
   get,
   set
}

Exceptions

Exception type Condition
HttpException The regular expression assigned was malformed.

Example

The following example demonstrates how to use the ValidationExpression property to set a validation expression for an e-mail address, telephone number, and URL.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 ' e-mail address validation
revEmail.ValidationExpression = "\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
' telephone number validation
revPhone.ValidationExpression = "((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}"
'/ URL validation
revURL.ValidationExpression = "http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?"

End Sub

[C#]

void Page_Load(Object sender, EventArgs e)
{
   // e-mail address validation
   revEmail.ValidationExpression = 
     "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
   // telephone number validation
   revPhone.ValidationExpression = 
     "((\\(\\d{3}\\) ?)|(\\d{3}-))?\\d{3}-\\d{4}";
   /// URL validation
   revURL.ValidationExpression = 
     "http://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?";
}   

See Also

Applies to: RegularExpressionValidator Class