Questions tagged [model-validation]

Model Validation is ASP.NET MVC validation method for your models with property attributes. Model validation works for client and server side validation.

For further information you can check Scott Gu's blog post: http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx

There is a expansion called "DATA ANNOTATIONS EXTENSIONS" for other custom validation types such as CreditCard, min-max integer value etc. http://weblogs.asp.net/srkirkland/archive/2011/02/23/introducing-data-annotations-extensions.aspx

325 questions
0
votes
0 answers

How to conditional validation apply on password in model

Developing rails 4 application where password is not compulsory validates :password, length: { in: 4..20 }, on: :create, :if => :check_provider def check_provider !self.provider.nil? end I put condition as you saw in above code but still…
user1780370
  • 851
  • 1
  • 17
  • 27
0
votes
1 answer

Wagtail/Django: This page could not be created due to validation errors

I have a little side project I'm working on that documents the history of racehorses, using Wagtail, a fairly new Django CMS. One of my model classes that I'm using for it (Gist of it is here) keeps encountering the above error. I'm fairly sure…
0
votes
1 answer

MVC Model Validation RegEx

I need a regex to be able to validate a domain name without http:// or https:// What I mean: Valid Should Be: domain.com domain.fr domain.it domain.whateverelse subdomain.domain.com subdomain.doamin.fr subdomain.domain.whateverelse Invalid Should…
David Dury
  • 5,537
  • 12
  • 56
  • 94
0
votes
1 answer

How to validate model of so string can be between 10 and 30 characters, or empty - C# ASP.NET

I'm trying to validate incoming JSON using the Required attribute on a model that contains phone numbers. There are two phone number properties, a Primary (required) and Alternate. For the Alternate, I want an empty string to be valid, but strings…
bubbleking
  • 3,329
  • 3
  • 29
  • 49
0
votes
2 answers

ValidationAttribute to verify the value is on the property a generic list

In our database we have several code tables that we use for referential integrity (ex emailTypes, phoneTypes, countryCodes, stateCodes). In our application we load and cache these tables into generic lists. Right now the application has custom…
0
votes
2 answers

Validation based on Conditions ASP.NET MVC

Am not sure if am repeating question but i didn't get exact answer for what am looking for Am having strongly typed view which i bind from model //Model [Required] public string sample { get; set; } public bool isAllowed { get; set; } Am…
Peru
  • 2,871
  • 5
  • 37
  • 66
0
votes
2 answers

Active Record Model Validation if email is blank or empty

In sign up page I want to validate user's email if user enter invalid email or email textbox left blank and want to show error message Enter your email address My User Model: VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i validates :email,…
0
votes
1 answer

How can I add injected custom validation attributes at runtime using Simple Injector?

First I have registered my custom attribute : container.Register(); I have created a custom DataAnnotationsModelValidatorProvider : public class CustomModelValidatorProvider :…
0
votes
1 answer

Cakephp declaring message in the Model Validation globally

iam using cakephp model validation. i want to display some validation error message in the model class var $validate = array( 'name' => array( 'notempty' => array( 'rule' => array('notempty'), 'message' =>…
SibinF
  • 385
  • 1
  • 7
  • 25
0
votes
2 answers

VallidationAttribute check multiple values in a condition

I'm still new to ASP.NET MVC and I'm struggling with a validator I need to implement. I have a UserName property in my Account model, that needs to be checked for uniqueness. It's declared as followed: [Required(ErrorMessageResourceName =…
FoxHound
  • 404
  • 5
  • 19
0
votes
1 answer

Model validation is checking required fields in a referenced model object, when the key is only required one

I'm creating an edit form for a Student model: public class Student { [Key] public virtual int ID { get; set; } [Required] public virtual StudentGuardian Guardian { get; set; } } This Student has a StudentGuardian instance inside,…
magdy.roshdy
  • 69
  • 1
  • 7
0
votes
1 answer

Asp.Net MVC model validation with default text in textbox

I am trying to validate input control in Asp.Net MVC. The below code checks if Project name is null and throws validation. I will have some default text in textbox on page load. I have a scenario to check if project name is not null and project name…
Kurkula
  • 6,386
  • 27
  • 127
  • 202
0
votes
0 answers

How to validate using annotations in a nested class

I'm trying to manually validate an object using its Data Annotations. Our models have the annotations in a nested class, so that they don't get overwritten when we automatically update them from the database schema. Let's say I have two…
Jk041
  • 934
  • 1
  • 15
  • 33
0
votes
1 answer

"[Required]" Data Annotation Not Enforced on POST Methods

I had the idea to use Data Annotations in order to validate ModelState. This works wonderfully. The problem I am having is that the [Required] Data Annotation is being enforced on [Key] fields on post. Our data layer takes care of setting Id's and…
0
votes
1 answer

Model Validations with RefineryCMS

Keep getting Syntax Error in Controller due to custom validations. Wondering how exactly I would implement custom validations within…
barnett
  • 1,572
  • 2
  • 13
  • 25