Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

TextMesh Pro InputField Character Validation using Regex

Discussion in 'UGUI & TextMesh Pro' started by tgaldi, Apr 10, 2018.

  1. tgaldi

    tgaldi

    Joined:
    Oct 28, 2015
    Posts:
    102
    Hi,

    I'm trying to use regex for an input field validator. Instead of writing a custom validator I would like to use the Regex Character Validation editor option. I'm using the following regex value for IP input:

    Code (CSharp):
    1. ^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$
    The expression can be found at https://www.regular-expressions.info/ip.html
    Doing so does not let me input anything into the field.
     
    Last edited: Apr 18, 2018
  2. tgaldi

    tgaldi

    Joined:
    Oct 28, 2015
    Posts:
    102
    Bump. Has anyone had success using the regex field in the input field component of TMP?
     
  3. Deleted User

    Deleted User

    Guest

    TMP does a Regex.IsMatch(ch.ToString(), m_RegexValue) in TMP_Inputfield.cs, what seems to be the problem: it should maybe use the whole text and not the last entered character. Your regex does not work, because "one" character may never satisfy such long regex, like yours.
     
    MilenaRocha and tgaldi like this.