|
4 | 4 | using System.Collections.Generic; |
5 | 5 | using System.Diagnostics; |
6 | 6 | using System.IO; |
| 7 | +using System.Text.RegularExpressions; |
7 | 8 | using System.Threading.Tasks; |
8 | 9 | using System.Windows; |
9 | 10 | using System.Windows.Input; |
@@ -40,6 +41,13 @@ private void Window_MouseDown(object sender, MouseButtonEventArgs e) |
40 | 41 |
|
41 | 42 | private async void build_MyBtnClickEvent(object sender, RoutedEventArgs e) |
42 | 43 | { |
| 44 | + var error = ValidateProjectName(); |
| 45 | + if (error != null) |
| 46 | + { |
| 47 | + MessageBox.Show(error); |
| 48 | + return; |
| 49 | + } |
| 50 | + |
43 | 51 | if (ProjectName == null || BuildPath == null) |
44 | 52 | { |
45 | 53 | MessageBox.Show("Please fill in all fields"); |
@@ -121,5 +129,30 @@ private void RadioButton_ChangedEvent(object sender, RoutedEventArgs e) |
121 | 129 | }; |
122 | 130 | } |
123 | 131 | } |
| 132 | + |
| 133 | + private string ValidateProjectName() |
| 134 | + { |
| 135 | + string result = null; |
| 136 | + |
| 137 | + if (string.IsNullOrEmpty(ProjectName)) |
| 138 | + { |
| 139 | + result = "Project name cannot be empty"; |
| 140 | + } |
| 141 | + else if (ProjectName.Length < 3) |
| 142 | + { |
| 143 | + result = "Project name must be at least 3 characters long"; |
| 144 | + } |
| 145 | + else if (ProjectName.Length > 50) |
| 146 | + { |
| 147 | + result = "Project name cannot be longer than 50 characters"; |
| 148 | + } |
| 149 | + else if (!Regex.IsMatch(ProjectName, @"^[a-z0-9_]+$")) |
| 150 | + { |
| 151 | + result = "Project name can only contain lowercase letters, numbers, and underscores"; |
| 152 | + |
| 153 | + } |
| 154 | + |
| 155 | + return result; |
| 156 | + } |
124 | 157 | } |
125 | 158 | } |
0 commit comments