Snaparazzi/Assets/Scripts/DatabaseClasses/Player.cs
2024-01-27 17:54:37 +01:00

39 lines
920 B
C#

using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
[System.Serializable]
public class Player
{
public string name;
public string id;
public Player(string _name)
{
id = System.Guid.NewGuid().ToString();
name = _name;
}
/// <summary>
/// Will sanitize the text and set it for the player
/// </summary>
public void SetName(string _name)
{
name = SanitizeString(_name);
}
private string SanitizeString(string input)
{
// Utilisez une expression régulière pour supprimer tout ce qui n'est pas une lettre ou un chiffre
string sanitized = Regex.Replace(input, @"[^a-zA-Z0-9]", "");
// Limitez la longueur à 16 caractères maximum
if (sanitized.Length > 16)
{
sanitized = sanitized.Substring(0, 16);
}
return sanitized;
}
}