How to validate a passport? [closed]

I don’t think you’re going to be able to do this without restricting yourself to certain issuing countries. If you look at the specs of machine readable passports: http://www.highprogrammer.com/alan/numbers/mrp.html It says that each country is free to use any format it likes for the actual passport number (including letters or digits). Although in the machine … Read more

What is the difference between Invariants and Validation Rules?

Absolutely, validation is the process of approving a given object state, while invariant enforcement happens before that state has even been reached. A corollary is that invariant enforcement is best performed by the thing that is being mutated (or created) itself, like a self-protection reflex, whereas validation is usually done by a third party. The … Read more

How to force MVC to Validate IValidatableObject

You can manually call Validate() by passing in a new instance of ValidationContext, like so: [HttpPost] public ActionResult Create(Model model) { if (!ModelState.IsValid) { var errors = model.Validate(new ValidationContext(model, null, null)); foreach (var error in errors) foreach (var memberName in error.MemberNames) ModelState.AddModelError(memberName, error.ErrorMessage); return View(post); } } A caveat of this approach is that in … Read more

Unique Constraints in Doctrine 2, Symfony 2

In the Table annotation, you can also set an index for multiple columns. /** * @ORM\Entity * @ORM\Table(name=”ecommerce_products”,uniqueConstraints={ * @ORM\UniqueConstraint(name=”search_idx”, columns={“name”, “email”})}) */ or with YAML format: Namespace\Entity\EntityName: type: entity table: ecommerce_products uniqueConstraints: uniqueConstraint: columns: [name, email]

Stop Fluent Validation on first failure

Just check for null before running the rules that depend on them, using a When condition. this.CascadeMode = CascadeMode.StopOnFirstFailure; RuleFor(x => x.TechnicalHeader).NotNull().WithMessage(“Header cannot be null”); // Ensure TechnicalHeader is provided When(x => x.TechnicalHeader != null, () => { RuleFor(x => x.TechnicalHeader.Userid).NotEmpty().WithMessage(“Userid cannot be null or an empty string”); RuleFor(x => x.TechnicalHeader.CabCode).GreaterThan(0).WithMessage(“CabCode cannot be or less … Read more

How to validate a property dependent on another property in Symfony 2

Starting from Symfony 2.4 you can also use Expression validation constraint to achieve what you need. I do believe, that this is the most simple way to do this. It’s more convenient than Callback constraint for sure. Here’s example of how you can update your model class with validation constraints annotations: use Symfony\Component\Validator\Constraints as Assert; … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)