-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOfflineAccountDialog.axaml.cs
More file actions
48 lines (41 loc) · 1.35 KB
/
Copy pathOfflineAccountDialog.axaml.cs
File metadata and controls
48 lines (41 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using Avalonia.Controls;
using Avalonia.Interactivity;
using System;
using System.Text.RegularExpressions;
namespace CitrineLauncher
{
public partial class OfflineAccountDialog : Window
{
public OfflineAccountDialog()
{
InitializeComponent();
}
public OfflineAccountDialog(string? existingUsername) : this()
{
if (!string.IsNullOrEmpty(existingUsername))
UsernameInput.Text = existingUsername;
}
private void CancelButton_Click(object? sender, RoutedEventArgs e)
{
Close(null);
}
private void AddButton_Click(object? sender, RoutedEventArgs e)
{
var username = UsernameInput.Text?.Trim() ?? string.Empty;
// Bug fix #18: validate username - Minecraft allows 3-16 alphanumeric + underscore
if (username.Length < 3 || username.Length > 16)
{
ErrorText.Text = "Username must be 3–16 characters.";
ErrorText.IsVisible = true;
return;
}
if (!Regex.IsMatch(username, @"^[a-zA-Z0-9_]+$"))
{
ErrorText.Text = "Only letters, numbers and underscores allowed.";
ErrorText.IsVisible = true;
return;
}
Close(username);
}
}
}