wpf - How to set maximum length of separated word of string property C# EF -


here part of model

public class sensor {     public int id { get; set; }      [required]     [maxlength(40)]     public string name { get; set; } } 

name text filed have maximum length of 40 symbols. , in text field possible have few words.

my question is possible set maximum length of word in name property?

for example have: "motion detector". , want word maximum 8 symbols. mean motion , detector need less of 8 symbols length. user can't write "motiondetector" length 12 symbols.

one way can use setter in property control max length per word:

set {   string[] words = value.split(' ')   if (words.any(x => x.length > 8)){       //error,   } else { //ok, pass       name = value; //only update name if length words valid   } } 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -