Search Unity

Automatically insert sth. when sth. is written into InputField

Discussion in 'Scripting' started by NotMyUsernameAgain, Dec 10, 2018.

  1. NotMyUsernameAgain

    NotMyUsernameAgain

    Joined:
    Sep 28, 2017
    Posts:
    139
    Hi everyone,

    I have an InputField where you can enter the date.
    What I want to achieve is, that the field automatically fills in "/" when you enter the digits.

    Eg. I enter 20181210
    and it automatically converts it to 2018/12/10 while typing.

    Or is there any other way I can achieve it?
    I only want a field where the date is more readable and you only need to enter the digits
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I would try setting a method to be called "On Value Changed" and have it parse and modify the contents of the input field's text component. I'd probably use a regex for parsing the typed contents, which you could also use for clearing out invalid characters while you're at it.

    https://docs.unity3d.com/Manual/script-InputField.html