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. Hi there! Do you use Twitter? I’d like to follow you if that would be okay. I’m absolutely enjoying your blog and look forward to new posts.

  2. Автор предлагает читателю разные взгляды на проблему, что способствует формированию собственного мнения.

  3. Я оцениваю использование автором разнообразных источников, чтобы подтвердить свои утверждения.

  4. I have learn a few good stuff here. Certainly price bookmarking for revisiting. I surprise how much attempt you put to make this sort of fantastic informative site.

  5. Я впечатлен этой статьей! Она не только информативна, но и вдохновляющая. Мне понравился подход автора к обсуждению темы, и я узнал много нового. Огромное спасибо за такую интересную и полезную статью!

  6. Информационная статья содержит полезный контент и представляет различные аспекты обсуждаемой темы.

  7. Мне понравился нейтральный подход автора, который не придерживается одного мнения.

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

  9. Я нашел в статье несколько интересных фактов, о которых раньше не знал.

  10. Я бы хотел отметить качество исследования, проведенного автором этой статьи. Он представил обширный объем информации, подкрепленный надежными источниками. Очевидно, что автор проявил большую ответственность в подготовке этой работы.

  11. My coder is trying to convince me to move to .net from PHP. I have always disliked the idea because of the costs. But he’s tryiong none the less. I’ve been using Movable-type on a number of websites for about a year and am nervous about switching to another platform. I have heard excellent things about blogengine.net. Is there a way I can transfer all my wordpress posts into it? Any help would be greatly appreciated!

  12. Я нашел в статье некоторые практические советы, которые можно применить в повседневной жизни.

  13. Wow, incredible blog layout! How long have you been blogging for? you made blogging look easy. The overall look of your website is fantastic, as well as the content!

  14. Я хотел бы выразить свою благодарность автору этой статьи за исчерпывающую информацию, которую он предоставил. Я нашел ответы на многие свои вопросы и получил новые знания. Это действительно ценный ресурс!

  15. It’s really a great and useful piece of info. I am happy that you shared this useful information with us. Please stay us up to date like this. Thank you for sharing.

  16. Мне понравилась четкая и последовательная логика аргументации автора в статье.

  17. Автор старается быть нейтральным, что помогает читателям лучше понять обсуждаемую тему.

  18. Статья предлагает широкий обзор событий и фактов, связанных с обсуждаемой темой.

  19. Я прочитал эту статью с огромным интересом! Автор умело объединил факты, статистику и персональные истории, что делает ее настоящей находкой. Я получил много новых знаний и вдохновения. Браво!

  20. I simply couldn’t depart your site before suggesting that I extremely enjoyed the usual information an individual provide to your guests? Is gonna be back incessantly to inspect new posts

  21. I needed to thank you for this very good read!! I definitely loved every little bit of it. I have you bookmarked to check out new stuff you post…

  22. Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.

  23. Mit Einsätzen zwischen fünf und 500 Euro können die Gäste täglich von 18.00 bis 02.30 Uhr an einem Tisch
    Black Jack spielen. Neben den Automatenspielen bietet die Spielbank in Lübeck eine
    Vielzahl an klassischen Tischspielen. Weitere Details zur Spielbank Lübeck werden auch
    bei onlinecasinosdeutschland.com vorgestellt.
    Das Spielcasino Lübeck überzeugt durch ein großes Angebot an vielen Automatenspielen und zahlreichen Tischspielen. Im Casino Lübeck haben die Gäste täglich die Möglichkeit, gegen die Bank das Ultimate Texas Hold’m zu spielen.
    Die Spielbank Lübeck bietet täglich von 12 Uhr bis 2.30 Uhr ein umfangreiches Spielangebot.

    Weiterhin bietet die Spielbank Lübeck auch zahlreiche Tischspiele und veranstaltet
    etliche Pokerturniere. Darüber hinaus bieten unsere exklusiven Veranstaltungen und Turniere aufregende
    Möglichkeiten, groß zu gewinnen, während unser VIP-Host-Programm
    ein personalisiertes Erlebnis bietet, das auf jeden Ihrer
    Wünsche zugeschnitten ist. Wer wirklich überall spielen will, der sollte einen Blick auf mobil optimierte Online Casinos werfen. Amerikanisches Roulette und
    Black Jack lassen sich auch hier im Herzen von St.
    Pauli spielen, allerdings wird kein Pokerspiel angeboten. Autofahrer
    können die Spielbank direkt über die A1 erreichen, die sich in unmittelbarer Nähe befindet und eine
    schnelle Anbindung bietet.

    References:
    https://online-spielhallen.de/evolve-casino-bonus-codes-ihr-umfassender-leitfaden/

  24. Статья предлагает широкий обзор событий и фактов, связанных с обсуждаемой темой.

  25. Wonderful beat ! I would like to apprentice whilst you amend your web site, how can i subscribe for a weblog website? The account aided me a acceptable deal. I have been a little bit acquainted of this your broadcast provided vibrant clear idea

  26. Я нашел в статье полезные источники, которые могу изучить для получения дополнительной информации.

  27. Эта статья является примером качественного исследования и профессионализма. Автор предоставил нам широкий обзор темы и представил информацию с точки зрения эксперта. Очень важный вклад в популяризацию знаний!

  28. Hello just wanted to give you a quick heads up. The text in your content seem to be running off the screen in Internet explorer. I’m not sure if this is a formatting issue or something to do with internet browser compatibility but I thought I’d post to let you know. The style and design look great though! Hope you get the issue fixed soon. Cheers

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>