ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Expression to detect text or number

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Omar Reyes
Expression to detect text or number
on Jan 24, 2020 at 7:31:29 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?


Return to posts index

Dan Ebberts
Re: Expression to detect text or number
on Jan 24, 2020 at 8:09:49 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



Return to posts index

Omar Reyes
Re: Expression to detect text or number
on Jan 24, 2020 at 9:19:26 pm

This is exactly what I was looking for! Thanks!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]