TMP_DigitValidator.cs 698 B

1234567891011121314151617181920212223242526
  1. using UnityEngine;
  2. using System;
  3. namespace TMPro
  4. {
  5. /// <summary>
  6. /// EXample of a Custom Character Input Validator to only allow digits from 0 to 9.
  7. /// </summary>
  8. [Serializable]
  9. //[CreateAssetMenu(fileName = "InputValidator - Digits.asset", menuName = "TextMeshPro/Input Validators/Digits", order = 100)]
  10. public class TMP_DigitValidator : TMP_InputValidator
  11. {
  12. // Custom text input validation function
  13. public override char Validate(ref string text, ref int pos, char ch)
  14. {
  15. if (ch >= '0' && ch <= '9')
  16. {
  17. pos += 1;
  18. return ch;
  19. }
  20. return (char)0;
  21. }
  22. }
  23. }