JavaScript test for integer / string

I couldn’t find either of these functions that satisfied my edge cases or desire for simplicity so I wrote/adapted some of my own. Feel free to use, modify, distribute without attribution, but I’d be eternally grateful if you did ;)

The test for integer is adapted from this post, which is actually almost spot on, apart from their is_int([0]) returns true, as does any integer in a string.

I’m pretty sure I’ve seen this test for string a hundred times on the internet and in books. It is by far the most robust:

Please let me know if you can break it!

422 thoughts on “JavaScript test for integer / string

  1. Читателям предоставляется возможность ознакомиться с фактами и самостоятельно сделать выводы.

  2. Эта статья оказалась исключительно информативной и понятной. Автор представил сложные концепции и теории в простой и доступной форме. Я нашел ее очень полезной и вдохновляющей!

  3. Lenovo Digital Workplace Solutions helps organizations quickly
    gain a competitive edge by relying on Lenovo-managed services that provide tailorable, people-focused work
    habitats. From pocket to cloud, individual to enterprise, Lenovo is taking AI out of abstract headlines
    and putting its power in the hands of real people, everywhere.
    Lenovo’s goal is to positively impact 15 million people by 2025 through the work of global
    philanthropy partnerships and programs, led by the Lenovo Foundation. From cities
    studded with edge computing cabinets that help stop traffic accidents to a ‘Cyber Space’ room where people interact with life-size objects on a transparent screen, our
    whole idea of computing is changing. Those innovations need to progress
    in harmony with our planet and its people, and so Lenovo prioritizes corporate citizenship in all
    that it does – from exploring net-zero emissions
    to global philanthropy. Lenovo is a global technology powerhouse,
    ranked at 196 in the Fortune Global 500,
    and a $69 billion revenue company that employs 77,000 people
    worldwide focused on delivering “smarter technology for all”.

    These rankings were used to create “reward models” that were used to fine-tune the model further
    by using several iterations of proximal policy optimization. The ethics
    of its development, particularly the use of copyrighted content as training data,
    have also drawn controversy. The chatbot can facilitate academic dishonesty, generate misinformation, and create malicious code.

    It uses generative pre-trained transformers (GPTs), such as
    GPT-5, to generate text, speech, and images in response
    to user prompts. ChatGPT is a generative artificial intelligence chatbot developed by OpenAI, and released
    in November 2022. By joining PHI Cares, you are becoming a member of a national air ambulance membership program that gives you peace of mind.

    GPT-5 was launched on August 7, 2025, and is publicly accessible through ChatGPT, Microsoft Copilot, and via OpenAI’s API.
    Released in February 2025, GPT-4.5 was described by Altman as a
    “giant, expensive model”. In September 2024, OpenAI introduced o1-preview and
    a faster, cheaper model named o1-mini. GPT-4o’s ability to generate images was
    released later, in March 2025, when it replaced DALL-E 3 in ChatGPT.
    GPT-4o (“o” for “omni”) is a multilingual, multimodal generative pre-trained transformer developed by OpenAI and released in May 2024.

    References:
    https://blackcoin.co/online-slots-in-australia/

  4. Автор представляет сложные темы в понятной и доступной форме для широкой аудитории.

  5. We might even see more personalized gaming
    experiences, withcustomizable lobbies that feel like your own private gaming lounge,AI-powered game recommendations that know exactly what you’ll love,
    andeven clever insights to help you sharpen your game and become a realpro.
    Think of this as yourcheat sheet to finding your
    ideal real money gaming adventure – noguesswork needed!
    The big focus here is always on providing a secure
    and efficientfinancial gateway, so you can just relax, breathe easy,
    and focus purelyon enjoying the RocketPlay casino games without a single worry aboutyour
    money! Online casinos, especially those as genuinelyplayer-focused as RocketPlay casino,
    are constantly dishing out enticingpromotions designed to reel
    in new players and, just as importantly,give a little love back
    to their loyal ones. Australia has this incredible, vibrant gambling
    culture, and whileonline platforms have been absolutely booming, that deep-seated cravingfor a genuine, high-quality casino experience never,
    ever fades.
    As one of the best online casino sites in Australia, RocketPlay offers
    an impressive collection of over 4,000 games from 48 leading software providers.
    If you’re looking to play online blackjack for real money, our dedicated section features multiple variations of this classic table game.
    The diverse range of casino bonuses available includes welcome
    bonuses, no deposit bonuses, and free spins,
    all aimed at enhancing your gaming experience.
    At RocketPlay, new players can also take advantage of a generous
    deposit bonus, which includes additional free spins and rewards, enhancing their gaming
    experience right from the start.
    It’s the same rocket play casino real money experience,
    just in your pocket. For players who want to enjoy rocketplay
    online casino without stressing over safety, the setup here holds up.
    And if you’re looking to rocketplay casino play online
    without babysitting your deposit, this one ticks the
    right boxes. The minimum deposit at RocketPlay Casino Australia
    is 30 AUD, giving members access to casino games, bonuses,
    and weekly rewards.

    References:
    https://blackcoin.co/getting-royal-panda-casino-bonus-without-depositing/

  6. whoah this blog is magnificent i love studying your articles. Stay up the great work! You know, a lot of people are looking around for this info, you could help them greatly.

  7. Автор старается оставаться объективным, чтобы читатели могли сформировать свое собственное мнение на основе предоставленной информации.

  8. Статья содержит аналитический подход к проблеме и представляет разнообразные точки зрения.

  9. Wonderful beat ! I would like to apprentice while you amend your website, how could i subscribe for a blog site? The account aided me a acceptable deal. I had been tiny bit acquainted of this your broadcast offered bright clear concept

  10. Это помогает читателям получить полную картину и сформировать собственное мнение на основе предоставленных фактов.

  11. My brother suggested I may like this web site. He was once totally right. This put up truly made my day. You can not imagine simply how so much time I had spent for this information! Thanks!

  12. I was recommended this web site by my cousin. I am not sure whether this post is written by him as nobody else know such detailed about my trouble. You’re amazing! Thanks!

  13. I was curious if you ever thought of changing the layout of your website? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having 1 or two images. Maybe you could space it out better?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>