iFactory.Godot/BITKit/Scripts/Text/RegularExpressionResource.cs

26 lines
558 B
C#
Raw Normal View History

using Godot;
using System;
using System.Runtime.InteropServices.ComTypes;
using System.Text.RegularExpressions;
using BITKit;
namespace BITKit;
[GlobalClass]
public partial class RegularExpressionResource : TextValidationResource
{
[Export] private string regex;
[Export] private string errorReason;
public override bool IsTextValid(string text, out string _errorReason)
{
switch (Regex.IsMatch(text, regex))
{
case true:
_errorReason = string.Empty;
return true;
case false:
_errorReason = errorReason;
return false;
}
}
}