Skip to content
Advertisement

How can I difference id (number) and email (string) in Javascript?

I have API and some of them return to only email and some return only id. For example:

user1 value: example@example.com

user2 value: 1212391361783212

I need that if I have input and wanna give value if the value is email. If the value is id, the input value must be null

JavaScript

Advertisement

Answer

Your code sample is incomplete but what you’re trying to do should look something like this. Rather than assuming any non-numerical response is a valid email, which can break in the future as the API changes, be explicit about what you’re looking for as below.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement