?
Solved

how to validate a textbox only allow integer, float number is not allowed?

Posted on 2005-04-19
4
Medium Priority
?
1,282 Views
Last Modified: 2012-06-21
Hi, all
I have a textbox which only allows users input a integer.
floating number is not allowed.

like 0.1, 0.009 are not allowed. How can i validated? currently I directly convert the float number into integer.

0
Comment
Question by:yangbin991
  • 2
4 Comments
 
LVL 19

Accepted Solution

by:
DreamMaster earned 200 total points
ID: 13814816
Try using:

If IsInteger(value) then
    Response.Write "That's correct, we have an integer"
else
    Response.Write "The value given was not an integer"
end if

With this being the IsInteger function

Function isInteger (number)
Dim result

if (IsNumeric(number)) then
   if (InStr(number,".")=0) then
      result=true
    else
      result=False
    end if
else
    result=False
end if

isInteger = result
End Function

Hope this helps,
Regards,
Max.
0
 
LVL 8

Expert Comment

by:sankarbha
ID: 13815928
You can do this in client side itself.

I have created a javascript function, which uses regexp for this validation.

All you have to do is call this isInteger function in your validation script.

      function isInteger(strText)
      {
            var reN = new RegExp("[0-9]");
            return reN.test(strText);
      }
0
 

Author Comment

by:yangbin991
ID: 13820896
both can work, because i am more familiar with vb. so give mark to DreamMaster. thank both
0
 
LVL 19

Expert Comment

by:DreamMaster
ID: 13823074
You're welcome yangbin991.

Glad to have been helpful,
Regards,
Max.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

807 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