ASP - quick check for positive integer value

Posted on 2006-04-28
Last Modified: 2008-02-01

I'm validating the contents of a form and need to check that one of the values is a positive integer. Is there an easy way to do this? I can check that it's numeric and that it's positive, but I'm a bit stumped on the integer bit. I basically need a function which will reject all non-integer values.

Thanks :-)

Question by:Nicola-H
    LVL 11

    Expert Comment

    Do you need a vbscript (asp) check or a clientside (javascript) check?
    LVL 11

    Expert Comment

    easiest way is probably to check for a decimalseparator in the string.

    LVL 44

    Accepted Solution

    Hi Nicola-H,

    Or simply check

    If n = int(n) Then
        'It is an integer

    Tim Cottee
    LVL 11

    Expert Comment

    tim's entry works, but it does assume you check serverside.
    LVL 1

    Author Comment

    Nice and simple - thanks Tim. It was server side code I needed, and unfortunately checking for decimal separators would not work in circumstamces where the idiot user entered bizarre strings of text. Some of the people who use these forms enter all manner of random carp.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
    This demonstration started out as a follow up to some recently posted questions on the subject of logging in: and…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now