Silverlight / WPF - Email Validation in silverlight XAML

Asked By Ramachandran on 07-Nov-11 04:51 AM
How to do a Email Validation in Silverlight Xaml in MVVM pattern using C #. plse help me with design and code examples
Reena Jain replied to Ramachandran on 07-Nov-11 07:51 AM

A ValidatioRule in a BindingExpression only triggers, when the target side of the binding changes. If you want to set a validation error by code you can use the following snippet.
ValidationError validationError =
  new ValidationError(regexValidationRule,
validationError.ErrorContent = "This is not a valid e-mail address";

Use ClearInvalid property of validation to clear the error


Hope this will help you
Robbe Morris replied to Ramachandran on 07-Nov-11 08:09 AM
Search on IValueConverter Email Regex in Google.  Those examples will show you how to bind the validator to your TextBox.
Riley K replied to Ramachandran on 08-Nov-11 12:16 AM

See how to use INotifyDataErrorInfo in an MVVM manner

for example

[Required(ErrorMessage = "Please provide an email address.")]
  [RegularExpression(@"^[\w\.=-]+@[\w\.-]+\.[\w]{2,3}$", ErrorMessage = "Please provide a valid email address.")]
  public string Email
    get { return _email; }
      _email = value;
      NotifyPropertyChanged(() => Email);

Refer this link

Kirtan Patel replied to Ramachandran on 17-Nov-11 11:48 AM
check out this good article that explain about validations in silver light

s j replied to Ramachandran on 18-Nov-11 04:37 AM


Hope this below site is useful for u.

Let me know if u have other queries regarding this.