views:

32

answers:

2

Hi All..

I have an issue with the implementation of VAB. We are using ASP.NET MVC 1.0

I have a property "First Name" and we want to have 2 validations.

  1. Not Null Validator
  2. RegEx Validator (to stop some characters)

Now if I leave it blank then it gives me the error message from both the validator. If the First name is blank I only want Not Null to show the error details If the First name is not blank then i was the RegEx to get executed and if there are any invalid characters then i want to stop them.

Please guide me here

Thanks !

A: 

The Not Null Validator is not going to pick it up because the string is not null - it is an empty string. Have a look at this post: http://geekswithblogs.net/michelotti/archive/2008/06/12/122836.aspx

Steve Michelotti
I am passing null value / empty string to the property and still both the validators are getting executed.
amit
I'm not sure I follow you when you say you are "passing null value / empty string" - you can *not* pass *both* a null value and empty string at the same time - this is not possible. You are saying if you pass *either* the same thing happens? Is this a web app? If so, you're not passing null value - you're passing empty string. Have you absolutely confirmed this?
Steve Michelotti
A: 

When you're using Enterprise Library 5.0, you can mix VAB attributes and DataAnnotation attributes (because VAB now extends DataAnnotations). When you decorate your property as follows, your problem is solved:

[System.ComponentModel.DataAnnotations.Required]
[EnterpriseLibrary.Validation.Validators.RegexValidator("...")]
public string LastName { get; set; }
Steven