Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression to detect text or number

  • Expression to detect text or number

    Posted by Omar Reyes on January 24, 2020 at 7:31 pm

    I’m working on making an AE template that imports data from a text file. Some fields are text and others are numbers and I have them linked to different text layers and expression controls in my project. This text file will be shared with multiple people and I’m trying to make it so if they accidentally enter a text string where a number is supposed to be, rather than popping up the expression error, it will assign the value as a 0.

    Is there an expression to check if the value is a text string or number?

    Omar Reyes replied 6 years, 7 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    January 24, 2020 at 8:09 pm

    If you’re using a text file, the numbers start out as text, correct? So (I.m guessing) your expression must be using parseInt() or parseFloat() to convert the text to a number. If so, you can use isNaN() after the conversion to see if it actually created a number. Like this:

    n = parseFloat(yourText);
    if (isNaN(n)) n = 0;
    n

    Dan

  • Omar Reyes

    January 24, 2020 at 9:19 pm

    This is exactly what I was looking for! Thanks!

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy