(ctx: &mut ValidationContext, field: &str, value: &str, chat_command: bool)
| 89 | } |
| 90 | |
| 91 | fn check_name_field(ctx: &mut ValidationContext, field: &str, value: &str, chat_command: bool) { |
| 92 | if value.chars().count() < 1 { |
| 93 | ctx.push_field_error(field, "has to be atleast 1 character".to_string()); |
| 94 | } |
| 95 | if value.chars().count() > 32 { |
| 96 | ctx.push_field_error(field, "can be max 32 characters long".to_string()); |
| 97 | } |
| 98 | |
| 99 | lazy_static! { |
| 100 | static ref RE: Regex = Regex::new(r#"^[\w-]+$"#).unwrap(); |
| 101 | static ref RERelaxed: Regex = Regex::new(r#"^[\w -]+$"#).unwrap(); |
| 102 | } |
| 103 | |
| 104 | if chat_command { |
| 105 | if !RE.is_match(value) { |
| 106 | ctx.push_field_error(field, "can only contain 'word' characters".to_string()); |
| 107 | } |
| 108 | |
| 109 | if value.to_lowercase() != value { |
| 110 | ctx.push_field_error(field, "has to be lower-case".to_string()); |
| 111 | } |
| 112 | } else { |
| 113 | if !RERelaxed.is_match(value) { |
| 114 | ctx.push_field_error(field, "can only contain 'word or space' characters".to_string()); |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | fn check_description_field(ctx: &mut ValidationContext, field: &str, value: &str) { |
| 120 | if value.chars().count() < 1 { |
no test coverage detected